"""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 = set(["scheme"])
        nullable_fields = set(["scheme"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            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
