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

from __future__ import annotations
from .cardscheme import CardScheme
from datetime import datetime
from gr4vy.types import BaseModel, Nullable, UNSET_SENTINEL
from gr4vy.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Dict, Literal, Optional
from typing_extensions import Annotated, TypedDict


class MerchantAccountThreeDSConfigurationTypedDict(TypedDict):
    merchant_acquirer_bin: str
    r"""Acquirer BIN to use when calling 3DS through this scheme."""
    merchant_acquirer_id: str
    r"""Merchant ID to use when calling 3DS through this scheme."""
    merchant_name: str
    merchant_country_code: str
    r"""The merchant's ISO 3166-1 numeric country code."""
    merchant_category_code: str
    r"""Merchant category code to use when calling 3DS through this scheme."""
    merchant_url: str
    r"""URL to send when calling 3DS through this scheme."""
    id: str
    r"""Unique identifier for the 3DS configuration"""
    merchant_account_id: str
    r"""ID of the associated merchant account"""
    created_at: datetime
    r"""The date and time when this 3DS configuration was first created in our system."""
    updated_at: datetime
    r"""The date and time when this 3DS configuration was last updated in our system."""
    scheme: CardScheme
    currency: Nullable[str]
    r"""ISO 4217 currency code (3 characters). If null, the configuration applies to all currencies."""
    metadata: Dict[str, str]
    r"""Additional information about the 3DS configuration, stored as key-value pairs."""
    type: Literal["merchant-account.three-ds-configuration"]
    r"""Always `merchant-account.three-ds-configuration`."""


class MerchantAccountThreeDSConfiguration(BaseModel):
    merchant_acquirer_bin: str
    r"""Acquirer BIN to use when calling 3DS through this scheme."""

    merchant_acquirer_id: str
    r"""Merchant ID to use when calling 3DS through this scheme."""

    merchant_name: str

    merchant_country_code: str
    r"""The merchant's ISO 3166-1 numeric country code."""

    merchant_category_code: str
    r"""Merchant category code to use when calling 3DS through this scheme."""

    merchant_url: str
    r"""URL to send when calling 3DS through this scheme."""

    id: str
    r"""Unique identifier for the 3DS configuration"""

    merchant_account_id: str
    r"""ID of the associated merchant account"""

    created_at: datetime
    r"""The date and time when this 3DS configuration was first created in our system."""

    updated_at: datetime
    r"""The date and time when this 3DS configuration was last updated in our system."""

    scheme: CardScheme

    currency: Nullable[str]
    r"""ISO 4217 currency code (3 characters). If null, the configuration applies to all currencies."""

    metadata: Dict[str, str]
    r"""Additional information about the 3DS configuration, stored as key-value pairs."""

    TYPE: Annotated[
        Annotated[
            Optional[Literal["merchant-account.three-ds-configuration"]],
            AfterValidator(validate_const("merchant-account.three-ds-configuration")),
        ],
        pydantic.Field(alias="type"),
    ] = "merchant-account.three-ds-configuration"
    r"""Always `merchant-account.three-ds-configuration`."""

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


try:
    MerchantAccountThreeDSConfiguration.model_rebuild()
except NameError:
    pass
