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

from __future__ import annotations
from .achtransactiondetails import ACHTransactionDetails, ACHTransactionDetailsTypedDict
from .applepayresponse import ApplePayResponse, ApplePayResponseTypedDict
from .cardtransactiondetails import (
    CardTransactionDetails,
    CardTransactionDetailsTypedDict,
)
from .transferaccount import TransferAccount, TransferAccountTypedDict
from .transferpaymentmethodsbankaccount import (
    TransferPaymentMethodsBankAccount,
    TransferPaymentMethodsBankAccountTypedDict,
)
from .transferpaymentmethodscard import (
    TransferPaymentMethodsCard,
    TransferPaymentMethodsCardTypedDict,
)
from .transferpaymentmethodswallet import (
    TransferPaymentMethodsWallet,
    TransferPaymentMethodsWalletTypedDict,
)
from .transferpaymentmethodtype import TransferPaymentMethodType
from .transferterminalcard import TransferTerminalCard, TransferTerminalCardTypedDict
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 TransferSourceTypedDict(TypedDict):
    payment_method_id: str
    payment_method_type: TransferPaymentMethodType
    r"""The payment method type that represents a payment rail and directionality"""
    account: TransferAccountTypedDict
    transfer_id: NotRequired[str]
    r"""String present only if the transfer is part of a transfer group."""
    bank_account: NotRequired[TransferPaymentMethodsBankAccountTypedDict]
    r"""A bank account as contained within a payment method."""
    wallet: NotRequired[TransferPaymentMethodsWalletTypedDict]
    card: NotRequired[TransferPaymentMethodsCardTypedDict]
    r"""A card as contained within a payment method."""
    apple_pay: NotRequired[ApplePayResponseTypedDict]
    r"""Describes an Apple Pay token on a Moov account."""
    terminal_card: NotRequired[TransferTerminalCardTypedDict]
    r"""Describes payment card details captured with tap or in-person payment."""
    card_details: NotRequired[CardTransactionDetailsTypedDict]
    r"""Card-specific details about the transaction."""
    ach_details: NotRequired[ACHTransactionDetailsTypedDict]
    r"""ACH specific details about the transaction."""


class TransferSource(BaseModel):
    payment_method_id: Annotated[str, pydantic.Field(alias="paymentMethodID")]

    payment_method_type: Annotated[
        TransferPaymentMethodType, pydantic.Field(alias="paymentMethodType")
    ]
    r"""The payment method type that represents a payment rail and directionality"""

    account: TransferAccount

    transfer_id: Annotated[Optional[str], pydantic.Field(alias="transferID")] = None
    r"""String present only if the transfer is part of a transfer group."""

    bank_account: Annotated[
        Optional[TransferPaymentMethodsBankAccount], pydantic.Field(alias="bankAccount")
    ] = None
    r"""A bank account as contained within a payment method."""

    wallet: Optional[TransferPaymentMethodsWallet] = None

    card: Optional[TransferPaymentMethodsCard] = None
    r"""A card as contained within a payment method."""

    apple_pay: Annotated[
        Optional[ApplePayResponse], pydantic.Field(alias="applePay")
    ] = None
    r"""Describes an Apple Pay token on a Moov account."""

    terminal_card: Annotated[
        Optional[TransferTerminalCard], pydantic.Field(alias="terminalCard")
    ] = None
    r"""Describes payment card details captured with tap or in-person payment."""

    card_details: Annotated[
        Optional[CardTransactionDetails], pydantic.Field(alias="cardDetails")
    ] = None
    r"""Card-specific details about the transaction."""

    ach_details: Annotated[
        Optional[ACHTransactionDetails], pydantic.Field(alias="achDetails")
    ] = None
    r"""ACH specific details about the transaction."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "transferID",
                "bankAccount",
                "wallet",
                "card",
                "applePay",
                "terminalCard",
                "cardDetails",
                "achDetails",
            ]
        )
        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:
    TransferSource.model_rebuild()
except NameError:
    pass
