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

from __future__ import annotations
from .cardscheme import CardScheme
from gr4vy.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing_extensions import NotRequired, TypedDict


class ThreeDSecureDataV1TypedDict(TypedDict):
    cavv: str
    r"""The cardholder authentication value or AAV."""
    eci: str
    r"""The ecommerce indicator for the 3DS transaction."""
    version: str
    r"""The version of 3-D Secure that was used."""
    directory_response: str
    r"""For 3-D Secure version 1, the enrolment response. For 3-D Secure version 2 and above, the transaction status from the `ARes`."""
    authentication_response: str
    r"""The response for the 3DS authentication call."""
    cavv_algorithm: str
    r"""The CAVV algorithm used."""
    xid: str
    r"""The transaction identifier."""
    scheme: NotRequired[Nullable[CardScheme]]
    r"""The scheme/brand of the card that is used for 3-D Secure."""


class ThreeDSecureDataV1(BaseModel):
    cavv: str
    r"""The cardholder authentication value or AAV."""

    eci: str
    r"""The ecommerce indicator for the 3DS transaction."""

    version: str
    r"""The version of 3-D Secure that was used."""

    directory_response: str
    r"""For 3-D Secure version 1, the enrolment response. For 3-D Secure version 2 and above, the transaction status from the `ARes`."""

    authentication_response: str
    r"""The response for the 3DS authentication call."""

    cavv_algorithm: str
    r"""The CAVV algorithm used."""

    xid: str
    r"""The transaction identifier."""

    scheme: OptionalNullable[CardScheme] = UNSET
    r"""The scheme/brand of the card that is used for 3-D Secure."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["scheme"]
        nullable_fields = ["scheme"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m
