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

from __future__ import annotations
from .e2eetokenupdate import E2EETokenUpdate, E2EETokenUpdateTypedDict
from .updatecardaddress import UpdateCardAddress, UpdateCardAddressTypedDict
from .updatecardexpiration import UpdateCardExpiration, UpdateCardExpirationTypedDict
from moovio_sdk.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class UpdateCardTypedDict(TypedDict):
    e2ee: NotRequired[E2EETokenUpdateTypedDict]
    r"""Wraps a compact-serialized JSON Web Encryption (JWE) token used for secure transmission of sensitive data (e.g., PCI information) through intermediaries.
    This token is encrypted using the public key from /end-to-end-keys and wraps an AES key. For details and examples, refer to our
    [GitHub repository](https://github.com/moovfinancial/moov-go/blob/main/examples/e2ee/e2ee_test.go).
    """
    billing_address: NotRequired[UpdateCardAddressTypedDict]
    r"""Updated billing address to store on file for the card."""
    expiration: NotRequired[UpdateCardExpirationTypedDict]
    card_cvv: NotRequired[str]
    r"""The card's 3- or 4-digit card verification value. Providing this triggers a new $0 verification authorization, which performs both CVV and address verification."""
    card_on_file: NotRequired[bool]
    r"""Indicates cardholder has authorized card to be stored for future payments (e.g., recurring payments).
    If true and no `merchantAccountID` is provided, the partner account's ID is automatically used as the merchant account for verification.
    """
    merchant_account_id: NotRequired[str]
    r"""Merchant account whose details (statement descriptor, address, etc.) are used for the card verification authorization.
    If omitted, the partner account's details are used instead.
    """
    verify_name: NotRequired[bool]
    r"""If true, submits the cardholder's name to the card network for verification as part of the $0 authorization.
    Only supported for Visa and Mastercard; requesting name verification for American Express or Discover will return an error.
    """
    holder_name: NotRequired[str]
    r"""Updated name of the cardholder as it appears on the card."""


class UpdateCard(BaseModel):
    e2ee: Optional[E2EETokenUpdate] = None
    r"""Wraps a compact-serialized JSON Web Encryption (JWE) token used for secure transmission of sensitive data (e.g., PCI information) through intermediaries.
    This token is encrypted using the public key from /end-to-end-keys and wraps an AES key. For details and examples, refer to our
    [GitHub repository](https://github.com/moovfinancial/moov-go/blob/main/examples/e2ee/e2ee_test.go).
    """

    billing_address: Annotated[
        Optional[UpdateCardAddress], pydantic.Field(alias="billingAddress")
    ] = None
    r"""Updated billing address to store on file for the card."""

    expiration: Optional[UpdateCardExpiration] = None

    card_cvv: Annotated[Optional[str], pydantic.Field(alias="cardCvv")] = None
    r"""The card's 3- or 4-digit card verification value. Providing this triggers a new $0 verification authorization, which performs both CVV and address verification."""

    card_on_file: Annotated[Optional[bool], pydantic.Field(alias="cardOnFile")] = None
    r"""Indicates cardholder has authorized card to be stored for future payments (e.g., recurring payments).
    If true and no `merchantAccountID` is provided, the partner account's ID is automatically used as the merchant account for verification.
    """

    merchant_account_id: Annotated[
        Optional[str], pydantic.Field(alias="merchantAccountID")
    ] = None
    r"""Merchant account whose details (statement descriptor, address, etc.) are used for the card verification authorization.
    If omitted, the partner account's details are used instead.
    """

    verify_name: Annotated[Optional[bool], pydantic.Field(alias="verifyName")] = None
    r"""If true, submits the cardholder's name to the card network for verification as part of the $0 authorization.
    Only supported for Visa and Mastercard; requesting name verification for American Express or Discover will return an error.
    """

    holder_name: Annotated[Optional[str], pydantic.Field(alias="holderName")] = None
    r"""Updated name of the cardholder as it appears on the card."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "e2ee",
                "billingAddress",
                "expiration",
                "cardCvv",
                "cardOnFile",
                "merchantAccountID",
                "verifyName",
                "holderName",
            ]
        )
        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


try:
    UpdateCard.model_rebuild()
except NameError:
    pass
