"""Type definitions for the MongolChat payment SDK."""

from dataclasses import dataclass, field
from typing import Any, List, Optional


# ── Configuration ──


@dataclass
class MongolChatConfig:
    """Configuration for MongolChatClient."""

    endpoint: str
    """MongolChat API base endpoint."""
    api_key: str
    """API key for the ``api-key`` header."""
    worker_key: str
    """Worker key for the ``Authorization: WorkerKey`` header."""
    app_secret: str
    """Application secret."""
    branch_no: str
    """Branch number."""


# ── Product ──


@dataclass
class MchatProduct:
    """A product item in a QR payment request."""

    product_name: str
    """Product name."""
    quantity: str
    """Quantity (string in the API)."""
    price: float
    """Price in MNT."""
    tag: str
    """Product tag / category."""


# ── QR Generate ──


@dataclass
class MchatGenerateQrInput:
    """Input for generating a QR code."""

    amount: float
    """Payment amount in MNT."""
    products: List[MchatProduct]
    """List of products."""
    title: str
    """Payment title."""
    sub_title: str
    """Payment subtitle."""
    noat: str
    """NOAT (VAT) number."""
    nhat: str
    """NHAT number."""
    ttd: str
    """TTD number."""
    reference_number: str
    """Unique reference number."""
    expire_time: str
    """QR expiration time."""
    branch_id: Optional[str] = None
    """Optional branch ID override."""


@dataclass
class MchatOnlineQrGenerateResponse:
    """Response from QR code generation."""

    qr: str
    """The generated QR code string."""
    code: int
    """Response code (1000 = success)."""
    message: str
    """Response message."""


# ── QR Check ──


@dataclass
class MchatOnlineQrCheckResponse:
    """Response from checking QR payment status."""

    status: str
    """Payment status."""
    code: int
    """Response code (1000 = success)."""
    message: str
    """Response message."""
    id: str
    """Transaction ID (populated when paid)."""
    who_paid: str
    """Who paid (populated when paid)."""
    user_ref_id: str
    """User reference ID (populated when paid)."""


# ── Webhook Types ──


@dataclass
class MchatWebhookScanQR:
    """Webhook payload for scan QR events."""

    reference_number: str
    who_paid: str
    user_ref_id: str
    transaction_id: str
    generated_qrcode: str
    amount: float
    date: str
    products: List[MchatProduct] = field(default_factory=list)


@dataclass
class MchatWebhookQuickpay:
    """Webhook payload for quickpay events."""

    reference_number: str
    who_paid: str
    user_ref_id: str
    transaction_id: str
    amount: float
    date: str
    products: List[MchatProduct] = field(default_factory=list)


@dataclass
class MchatWebhookOrder:
    """Webhook payload for order events."""

    reference_number: str
    who_paid: str
    user_ref_id: str
    transaction_id: str
    order_id: str
    amount: float
    date: str
    products: List[MchatProduct] = field(default_factory=list)


@dataclass
class MchatWebhookInput:
    """Raw webhook input envelope."""

    type: str
    """Webhook event type."""
    data: Any = None
    """Webhook event data."""
