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

from __future__ import annotations
from flexprice.types import BaseModel, UNSET_SENTINEL
from flexprice.utils import FieldMetadata, QueryParamMetadata
from pydantic import model_serializer
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


ListPaymentsOrder = Literal[
    "asc",
    "desc",
]


ListPaymentsStatus = Literal[
    "published",
    "deleted",
    "archived",
]


class ListPaymentsRequestTypedDict(TypedDict):
    currency: NotRequired[str]
    destination_id: NotRequired[str]
    destination_type: NotRequired[str]
    end_time: NotRequired[str]
    expand: NotRequired[str]
    gateway_payment_id: NotRequired[str]
    gateway_tracking_id: NotRequired[str]
    r"""For filtering by gateway tracking ID"""
    limit: NotRequired[int]
    offset: NotRequired[int]
    order: NotRequired[ListPaymentsOrder]
    payment_gateway: NotRequired[str]
    payment_ids: NotRequired[List[str]]
    payment_method_type: NotRequired[str]
    payment_status: NotRequired[str]
    sort: NotRequired[str]
    start_time: NotRequired[str]
    status: NotRequired[ListPaymentsStatus]


class ListPaymentsRequest(BaseModel):
    currency: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    destination_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    destination_type: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    end_time: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    expand: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    gateway_payment_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    gateway_tracking_id: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""For filtering by gateway tracking ID"""

    limit: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    offset: Annotated[
        Optional[int],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    order: Annotated[
        Optional[ListPaymentsOrder],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    payment_gateway: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    payment_ids: Annotated[
        Optional[List[str]],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=False)),
    ] = None

    payment_method_type: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    payment_status: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    sort: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    start_time: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "currency",
                "destination_id",
                "destination_type",
                "end_time",
                "expand",
                "gateway_payment_id",
                "gateway_tracking_id",
                "limit",
                "offset",
                "order",
                "payment_gateway",
                "payment_ids",
                "payment_method_type",
                "payment_status",
                "sort",
                "start_time",
                "status",
            ]
        )
        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
