"""Event definitions for the transactions domain."""

from typing import List, Dict

TRANSACTION_EVENTS: List[Dict] = [
    {
        "event_id": "transaction.completed",
        "event_name": "Transaction Completed",
        "description": (
            "Emitted after a transaction is successfully charged.  Consumed by "
            "the invoices listener (mark invoice PAID) and the notifications "
            "listener (send payment receipt)."
        ),
        "topic": "payment_events_transactions",
        "data_contract": {
            "transaction_id": "int",
            "txn_id": "str — provider-assigned transaction ID",
            "txn_amount": "float",
            "payment_request_id": "int",
            "merchant_id": "int",
            "customer_id": "int",
            "is_scheduled": "bool — True if this was a scheduled installment",
            "is_retry": "bool — True if this completed a retry flow",
        },
    },
    {
        "event_id": "transaction.failed",
        "event_name": "Transaction Failed",
        "description": (
            "Emitted when a transaction charge fails.  Consumed by the "
            "transactions listener (update PR status, create retry token) and "
            "the notifications listener (send failed-payment + retry link)."
        ),
        "topic": "payment_events_transactions",
        "data_contract": {
            "transaction_id": "int",
            "txn_amount": "float",
            "payment_request_id": "int",
            "merchant_id": "int",
            "customer_id": "int",
            "retry_token": "str | None — populated by merchant-triggered retry",
            "retry_link": "str | None — full retry URL for customer",
            "is_merchant_triggered": "bool",
        },
    },
    {
        "event_id": "transaction.submitted",
        "event_name": "Transaction Submitted",
        "description": (
            "Emitted immediately after a charge is submitted to the active "
            "payment provider but before the provider response is received.  "
            "Useful for audit trails and provider latency monitoring."
        ),
        "topic": "payment_events_transactions",
        "data_contract": {
            "payment_request_id": "int",
            "merchant_id": "int",
            "provider_slug": "str — slug of the active provider (e.g. 'payrix')",
            "amount": "float",
            "currency": "str",
            "provider_reference_id": "str — idempotency key sent to provider",
        },
    },
    {
        "event_id": "transaction.refunded",
        "event_name": "Transaction Refunded",
        "description": (
            "Emitted after a refund is successfully processed by the active "
            "payment provider.  Consumed by the invoices listener to update "
            "invoice status."
        ),
        "topic": "payment_events_transactions",
        "data_contract": {
            "transaction_id": "int",
            "payment_request_id": "int",
            "merchant_id": "int",
            "refund_amount": "float",
            "currency": "str",
        },
    },
    {
        "event_id": "transaction.scheduled",
        "event_name": "Transaction Scheduled",
        "description": (
            "Emitted when a future-dated installment transaction is queued via "
            "Celery.  No immediate payment is taken; process_scheduled_payment "
            "will emit transaction.completed or transaction.failed when the "
            "billing date arrives."
        ),
        "topic": "payment_events_transactions",
        "data_contract": {
            "transaction_id": "int",
            "txn_amount": "float",
            "payment_request_id": "int",
            "merchant_id": "int",
            "customer_id": "int",
            "scheduled_at": "ISO8601 datetime — when the Celery task is scheduled to run",
        },
    },
]
