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

from __future__ import annotations
from gr4vy.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from gr4vy.utils import FieldMetadata, HeaderMetadata, QueryParamMetadata
import pydantic
from pydantic import model_serializer
from typing import Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


class ListBuyerPaymentMethodsGlobalsTypedDict(TypedDict):
    merchant_account_id: NotRequired[str]
    r"""The ID of the merchant account to use for this request."""


class ListBuyerPaymentMethodsGlobals(BaseModel):
    merchant_account_id: Annotated[
        Optional[str],
        pydantic.Field(alias="x-gr4vy-merchant-account-id"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The ID of the merchant account to use for this request."""

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


SortBy = Literal[
    "last_used_at",
    "usage_count",
    "cit_last_used_at",
    "cit_usage_count",
]
r"""The field to sort the payment methods by."""


OrderBy = Union[
    Literal[
        "asc",
        "desc",
    ],
    UnrecognizedStr,
]
r"""The direction to sort the payment methods in."""


class ListBuyerPaymentMethodsRequestTypedDict(TypedDict):
    buyer_id: NotRequired[Nullable[str]]
    r"""The ID of the buyer to query payment methods for."""
    buyer_external_identifier: NotRequired[Nullable[str]]
    r"""The external identifier of the buyer to query payment methods for."""
    sort_by: NotRequired[Nullable[SortBy]]
    r"""The field to sort the payment methods by."""
    order_by: NotRequired[OrderBy]
    r"""The direction to sort the payment methods in."""
    country: NotRequired[Nullable[str]]
    r"""The country code to filter payment methods by. This only applies to payment methods with a `country` value."""
    currency: NotRequired[Nullable[str]]
    r"""The currency code to filter payment methods by. This only applies to payment methods with a `currency` value."""
    merchant_account_id: NotRequired[str]
    r"""The ID of the merchant account to use for this request."""


class ListBuyerPaymentMethodsRequest(BaseModel):
    buyer_id: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""The ID of the buyer to query payment methods for."""

    buyer_external_identifier: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""The external identifier of the buyer to query payment methods for."""

    sort_by: Annotated[
        OptionalNullable[SortBy],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""The field to sort the payment methods by."""

    order_by: Annotated[
        Optional[OrderBy],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = "desc"
    r"""The direction to sort the payment methods in."""

    country: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""The country code to filter payment methods by. This only applies to payment methods with a `country` value."""

    currency: Annotated[
        OptionalNullable[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = UNSET
    r"""The currency code to filter payment methods by. This only applies to payment methods with a `currency` value."""

    merchant_account_id: Annotated[
        Optional[str],
        pydantic.Field(alias="x-gr4vy-merchant-account-id"),
        FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
    ] = None
    r"""The ID of the merchant account to use for this request."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "buyer_id",
                "buyer_external_identifier",
                "sort_by",
                "order_by",
                "country",
                "currency",
                "merchant_account_id",
            ]
        )
        nullable_fields = set(
            ["buyer_id", "buyer_external_identifier", "sort_by", "country", "currency"]
        )
        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))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

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

        return m
