"""Email notifications for supplier events."""

from __future__ import annotations

from apps.core.email import EmailService


def notify_supplier_payment_success(user, payment_data: dict) -> bool:
    """Send an email to the supplier when a payment is successfully received.

    Args:
        user: The supplier's User instance (has email, full_name).
        payment_data: The verified GetPaymentStatus response dict.

    Returns:
        True if sent successfully.
    """
    invoice_id = payment_data.get("InvoiceId", "")
    invoice_value = payment_data.get("InvoiceDisplayValue", "")
    customer_name = payment_data.get("CustomerName", "")
    invoice_reference = payment_data.get("InvoiceReference", "")

    return EmailService.send(
        to=user.email,
        subject=f"Payment Received — Invoice #{invoice_id}",
        message=(
            f"Hi {user.full_name or user.email},\n\n"
            f"A payment has been successfully received.\n\n"
            f"Details:\n"
            f"  Invoice ID: {invoice_id}\n"
            f"  Reference: {invoice_reference}\n"
            f"  Customer: {customer_name}\n"
            f"  Amount: {invoice_value}\n\n"
            f"You can view the full details in your supplier portal.\n\n"
            f"— RfoofPay"
        ),
        fail_silently=False,
    )
