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

from __future__ import annotations
from gr4vy.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from gr4vy.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Any, Literal
from typing_extensions import Annotated, NotRequired, TypedDict


class GooglePayFPANPaymentMethodCreateTypedDict(TypedDict):
    r"""Create a Google Pay payment with an FPAN."""

    expiration_date: str
    r"""The expiration date of the card, formatted `MM/YY`."""
    number: str
    r"""The 13-19 digit number for this card."""
    buyer_external_identifier: NotRequired[Nullable[str]]
    r"""The external identifier of the buyer to attach the method to."""
    buyer_id: NotRequired[Nullable[str]]
    r"""The ID of the buyer to attach the method to."""
    external_identifier: NotRequired[Nullable[str]]
    r"""The merchant reference for this payment method."""
    card_type: NotRequired[Nullable[str]]
    r"""The type of the card used"""
    method: Literal["googlepay_pan_only"]
    r"""Aways `googlepay_pan_only`."""
    redirect_url: NotRequired[Nullable[str]]
    r"""The URL to redirect a user back to after the complete 3DS in browser."""
    security_code: NotRequired[Nullable[Any]]
    r"""The 3 or 4 digit security code often found on the card. This often referred to as the CVV or CVD."""


class GooglePayFPANPaymentMethodCreate(BaseModel):
    r"""Create a Google Pay payment with an FPAN."""

    expiration_date: str
    r"""The expiration date of the card, formatted `MM/YY`."""

    number: str
    r"""The 13-19 digit number for this card."""

    buyer_external_identifier: OptionalNullable[str] = UNSET
    r"""The external identifier of the buyer to attach the method to."""

    buyer_id: OptionalNullable[str] = UNSET
    r"""The ID of the buyer to attach the method to."""

    external_identifier: OptionalNullable[str] = UNSET
    r"""The merchant reference for this payment method."""

    card_type: OptionalNullable[str] = UNSET
    r"""The type of the card used"""

    METHOD: Annotated[
        Annotated[
            Literal["googlepay_pan_only"],
            AfterValidator(validate_const("googlepay_pan_only")),
        ],
        pydantic.Field(alias="method"),
    ] = "googlepay_pan_only"
    r"""Aways `googlepay_pan_only`."""

    redirect_url: OptionalNullable[str] = UNSET
    r"""The URL to redirect a user back to after the complete 3DS in browser."""

    security_code: OptionalNullable[Any] = UNSET
    r"""The 3 or 4 digit security code often found on the card. This often referred to as the CVV or CVD."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "buyer_external_identifier",
                "buyer_id",
                "external_identifier",
                "card_type",
                "redirect_url",
                "security_code",
            ]
        )
        nullable_fields = set(
            [
                "buyer_external_identifier",
                "buyer_id",
                "external_identifier",
                "card_type",
                "redirect_url",
                "security_code",
            ]
        )
        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
