"""Event definitions for the checkouts domain."""
from typing import List, Dict

CHECKOUT_EVENTS: List[Dict] = [
    {
        "event_id": "checkout.created",
        "event_name": "Checkout Created",
        "description": "Emitted after a Checkout record is created. Consumed by the checkout listener to write an activity record.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/services.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "merchant_id": "int",
            "checkout_literal": "str",
            "checkout_type": "str",
        },
    },
    {
        "event_id": "checkout.activated",
        "event_name": "Checkout Activated",
        "description": "Emitted when a checkout is set to ACTIVE status and a link token is generated.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/services.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "merchant_id": "int",
            "link_token": "str",
        },
    },
    {
        "event_id": "checkout.deactivated",
        "event_name": "Checkout Deactivated",
        "description": "Emitted when a checkout is set to INACTIVE and its link is revoked.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/services.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "merchant_id": "int",
        },
    },
    {
        "event_id": "checkout.expired",
        "event_name": "Checkout Expired",
        "description": "Emitted by Celery task when an ACTIVE checkout passes its expires_at.",
        "topic": "payment_events_checkouts",
        "emitted_by": "worker/tasks/expire_checkouts.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "merchant_id": "int",
            "expires_at": "ISO8601 datetime string",
        },
    },
    {
        "event_id": "checkout.shared",
        "event_name": "Checkout Shared",
        "description": "Emitted when a merchant shares a checkout via email/SMS. Triggers notification sends.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/services.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "merchant_id": "int",
            "recipients": "dict",
            "channels": "list[str]",
        },
    },
    {
        "event_id": "checkout.viewed",
        "event_name": "Checkout Viewed",
        "description": "Emitted when a payer visits the public checkout URL. Increments click_count.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/public_router.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "token": "str",
            "ip_address": "str | None",
        },
    },
    {
        "event_id": "checkout.payment_completed",
        "event_name": "Checkout Payment Completed",
        "description": "Emitted when a transaction linked to a checkout is completed. Triggers receipt and activity log.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/listener.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "payment_request_id": "int",
            "merchant_id": "int",
            "customer_id": "int | None",
            "amount": "float",
            "tip_amount": "float",
        },
    },
    {
        "event_id": "checkout.payment_authorized",
        "event_name": "Checkout Payment Authorized",
        "description": "Emitted when a deferred/recurring payment is authorized through a checkout.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/listener.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "payment_request_id": "int",
            "merchant_id": "int",
            "customer_id": "int | None",
            "amount": "float",
            "scheduled_date": "ISO8601 date string | None",
        },
    },
    {
        "event_id": "checkout.link_regenerated",
        "event_name": "Checkout Link Regenerated",
        "description": "Emitted when a merchant regenerates the checkout link token.",
        "topic": "payment_events_checkouts",
        "emitted_by": "checkouts/services.py",
        "consumed_by": ["checkouts/listener.py"],
        "data_contract": {
            "checkout_id": "int",
            "merchant_id": "int",
            "old_token": "str | None",
            "new_token": "str",
        },
    },
]
