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

from __future__ import annotations
from .offsetpagination import OffsetPagination, OffsetPaginationTypedDict
from .payment import Payment, PaymentTypedDict
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL
from paygentic_sdk.utils import FieldMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


ListPaymentsStatus = Literal[
    "pending",
    "processing",
    "completed",
    "expired",
    "cancelled",
]
r"""Filter by payment status."""


class ListPaymentsRequestTypedDict(TypedDict):
    merchant_id: NotRequired[str]
    r"""Merchant organization ID. Required when using an API key that is not scoped to a single merchant."""
    status: NotRequired[ListPaymentsStatus]
    r"""Filter by payment status."""
    customer_id: NotRequired[str]
    r"""Filter by customer ID."""
    limit: NotRequired[int]
    r"""Number of payments to return."""
    offset: NotRequired[int]
    r"""Number of payments to skip."""


class ListPaymentsRequest(BaseModel):
    merchant_id: Annotated[
        Optional[str],
        pydantic.Field(alias="merchantId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Merchant organization ID. Required when using an API key that is not scoped to a single merchant."""

    status: Annotated[
        Optional[ListPaymentsStatus],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by payment status."""

    customer_id: Annotated[
        Optional[str],
        pydantic.Field(alias="customerId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter by customer ID."""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 10
    r"""Number of payments to return."""

    offset: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = 0
    r"""Number of payments to skip."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["merchantId", "status", "customerId", "limit", "offset"])
        serialized = handler(self)
        m = {}

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

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

        return m


ListPaymentsObject = Literal["list",]


class ListPaymentsResponseTypedDict(TypedDict):
    r"""List of payments"""

    object: ListPaymentsObject
    data: List[PaymentTypedDict]
    pagination: OffsetPaginationTypedDict
    r"""Offset-based pagination response."""


class ListPaymentsResponse(BaseModel):
    r"""List of payments"""

    object: ListPaymentsObject

    data: List[Payment]

    pagination: OffsetPagination
    r"""Offset-based pagination response."""
