"""
Utilitaires partagés : vérifier si un user a payé pour un type de document.
"""
from .models import DocumentPurchase


def user_has_paid_for_document(user, document_type: str) -> bool:
    """True si l'utilisateur a un achat completed pour ce type (bp, bmc, pitch)."""
    if not user or not user.is_authenticated:
        return False
    doc_type = (document_type or "").strip().lower()
    if doc_type not in ("bp", "bmc", "pitch"):
        return False
    return DocumentPurchase.objects.filter(
        user=user,
        document_type=doc_type,
        status="completed",
    ).exists()
