"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from datetime import datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL, UnrecognizedStr
import pydantic
from pydantic import model_serializer
from typing import Dict, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


PaymentObject = Literal["payment",]


class LineItemTypedDict(TypedDict):
    description: NotRequired[str]
    amount: NotRequired[str]
    quantity: NotRequired[int]


class LineItem(BaseModel):
    description: Optional[str] = None

    amount: Optional[str] = None

    quantity: Optional[int] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["description", "amount", "quantity"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


PaymentStatus = Union[
    Literal[
        "pending",
        "processing",
        "completed",
        "expired",
        "cancelled",
    ],
    UnrecognizedStr,
]
r"""Current status of the payment."""


class PaymentTypedDict(TypedDict):
    id: str
    r"""Unique payment identifier (pay_* prefixed)."""
    amount: str
    r"""Payment amount in decimal format (e.g. '10.50')."""
    currency: str
    r"""ISO 4217 currency code (e.g. 'USD')."""
    status: PaymentStatus
    r"""Current status of the payment."""
    created_at: datetime
    r"""When the payment was created."""
    object: NotRequired[PaymentObject]
    payment_url: NotRequired[str]
    r"""URL for the customer to complete the payment."""
    customer_id: NotRequired[str]
    r"""Customer ID if provided."""
    idempotency_key: NotRequired[str]
    r"""Client-provided idempotency key."""
    reference: NotRequired[str]
    r"""Merchant-defined reference for this payment."""
    metadata: NotRequired[Dict[str, str]]
    r"""Merchant-provided key-value metadata."""
    line_items: NotRequired[List[LineItemTypedDict]]
    r"""Breakdown of what the customer is being charged for."""
    expires_at: NotRequired[datetime]
    r"""When the payment expires."""


class Payment(BaseModel):
    id: str
    r"""Unique payment identifier (pay_* prefixed)."""

    amount: str
    r"""Payment amount in decimal format (e.g. '10.50')."""

    currency: str
    r"""ISO 4217 currency code (e.g. 'USD')."""

    status: PaymentStatus
    r"""Current status of the payment."""

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]
    r"""When the payment was created."""

    object: Optional[PaymentObject] = "payment"

    payment_url: Annotated[Optional[str], pydantic.Field(alias="paymentUrl")] = None
    r"""URL for the customer to complete the payment."""

    customer_id: Annotated[Optional[str], pydantic.Field(alias="customerId")] = None
    r"""Customer ID if provided."""

    idempotency_key: Annotated[
        Optional[str], pydantic.Field(alias="idempotencyKey")
    ] = None
    r"""Client-provided idempotency key."""

    reference: Optional[str] = None
    r"""Merchant-defined reference for this payment."""

    metadata: Optional[Dict[str, str]] = None
    r"""Merchant-provided key-value metadata."""

    line_items: Annotated[
        Optional[List[LineItem]], pydantic.Field(alias="lineItems")
    ] = None
    r"""Breakdown of what the customer is being charged for."""

    expires_at: Annotated[Optional[datetime], pydantic.Field(alias="expiresAt")] = None
    r"""When the payment expires."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "object",
                "paymentUrl",
                "customerId",
                "idempotencyKey",
                "reference",
                "metadata",
                "lineItems",
                "expiresAt",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    Payment.model_rebuild()
except NameError:
    pass
