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

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


Currency = Literal[
    "USD",
    "EUR",
    "GBP",
    "AUD",
]
r"""ISO 4217 currency code."""


class CreatePaymentLineItemTypedDict(TypedDict):
    description: str
    r"""Line item description."""
    amount: str
    r"""Line item amount in decimal format (e.g. '5.00')."""
    quantity: NotRequired[int]
    r"""Quantity of this line item. Defaults to 1."""


class CreatePaymentLineItem(BaseModel):
    description: str
    r"""Line item description."""

    amount: str
    r"""Line item amount in decimal format (e.g. '5.00')."""

    quantity: Optional[int] = 1
    r"""Quantity of this line item. Defaults to 1."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["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


class CreatePaymentRequestTypedDict(TypedDict):
    amount: str
    r"""Payment amount in decimal format (e.g. '10.50'). Minimum 1.00, maximum 5,000.00. Contact support for higher limits."""
    currency: Currency
    r"""ISO 4217 currency code."""
    merchant_id: NotRequired[str]
    r"""Merchant organization ID. Required when using an API key that is not scoped to a single merchant."""
    customer_id: NotRequired[str]
    r"""Optional customer ID. Must belong to this merchant."""
    idempotency_key: NotRequired[str]
    r"""Client-provided key for safe retries. If a payment with the same key already exists, the existing payment is returned."""
    reference: NotRequired[str]
    r"""Merchant-defined reference for this payment (e.g. order ID, invoice number)."""
    metadata: NotRequired[Dict[str, str]]
    r"""Arbitrary key-value string pairs to attach to the payment."""
    line_items: NotRequired[List[CreatePaymentLineItemTypedDict]]
    r"""Optional breakdown of what the customer is being charged for."""
    success_redirect_url: NotRequired[str]
    r"""URL to redirect the customer to after a successful payment."""
    failure_redirect_url: NotRequired[str]
    r"""URL to redirect the customer to after a failed payment."""
    save_payment_method: NotRequired[bool]
    r"""Whether to save the customer's payment method for future use. Defaults to false."""
    expires_in: NotRequired[str]
    r"""ISO 8601 duration for the payment lifetime. Defaults to P30D (30 days). Maximum is P31D (31 days). Examples: PT1H, P1D, P7D, P30D."""


class CreatePaymentRequest(BaseModel):
    amount: str
    r"""Payment amount in decimal format (e.g. '10.50'). Minimum 1.00, maximum 5,000.00. Contact support for higher limits."""

    currency: Currency
    r"""ISO 4217 currency code."""

    merchant_id: Annotated[Optional[str], pydantic.Field(alias="merchantId")] = None
    r"""Merchant organization ID. Required when using an API key that is not scoped to a single merchant."""

    customer_id: Annotated[Optional[str], pydantic.Field(alias="customerId")] = None
    r"""Optional customer ID. Must belong to this merchant."""

    idempotency_key: Annotated[
        Optional[str], pydantic.Field(alias="idempotencyKey")
    ] = None
    r"""Client-provided key for safe retries. If a payment with the same key already exists, the existing payment is returned."""

    reference: Optional[str] = None
    r"""Merchant-defined reference for this payment (e.g. order ID, invoice number)."""

    metadata: Optional[Dict[str, str]] = None
    r"""Arbitrary key-value string pairs to attach to the payment."""

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

    success_redirect_url: Annotated[
        Optional[str], pydantic.Field(alias="successRedirectUrl")
    ] = None
    r"""URL to redirect the customer to after a successful payment."""

    failure_redirect_url: Annotated[
        Optional[str], pydantic.Field(alias="failureRedirectUrl")
    ] = None
    r"""URL to redirect the customer to after a failed payment."""

    save_payment_method: Annotated[
        Optional[bool], pydantic.Field(alias="savePaymentMethod")
    ] = False
    r"""Whether to save the customer's payment method for future use. Defaults to false."""

    expires_in: Annotated[Optional[str], pydantic.Field(alias="expiresIn")] = None
    r"""ISO 8601 duration for the payment lifetime. Defaults to P30D (30 days). Maximum is P31D (31 days). Examples: PT1H, P1D, P7D, P30D."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "merchantId",
                "customerId",
                "idempotencyKey",
                "reference",
                "metadata",
                "lineItems",
                "successRedirectUrl",
                "failureRedirectUrl",
                "savePaymentMethod",
                "expiresIn",
            ]
        )
        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:
    CreatePaymentRequest.model_rebuild()
except NameError:
    pass
