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

from __future__ import annotations
from ascend_sdk import utils
from ascend_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from ascend_sdk.utils import validate_open_enum
from enum import Enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CalculateCashBalanceResponseTransferSummaryAmountTypedDict(TypedDict):
    r"""The amount of the transfer in USD. The value will be positive for deposits and negative for withdrawals."""

    value: NotRequired[str]
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class CalculateCashBalanceResponseTransferSummaryAmount(BaseModel):
    r"""The amount of the transfer in USD. The value will be positive for deposits and negative for withdrawals."""

    value: Optional[str] = None
    r"""The decimal value, as a string; Refer to [Google’s Decimal type protocol buffer](https://github.com/googleapis/googleapis/blob/40203ca1880849480bbff7b8715491060bbccdf1/google/type/decimal.proto#L33) for details"""


class CalculateCashBalanceResponseTransferSummaryMechanism(
    str, Enum, metaclass=utils.OpenEnumMeta
):
    r"""The mechanism of the transfer."""

    MECHANISM_UNSPECIFIED = "MECHANISM_UNSPECIFIED"
    ACAT = "ACAT"
    ACH = "ACH"
    CASH_JOURNAL = "CASH_JOURNAL"
    CHECK = "CHECK"
    CREDIT = "CREDIT"
    FEE = "FEE"
    ICT = "ICT"
    PAYPAL = "PAYPAL"
    RTP = "RTP"
    TPJ = "TPJ"
    WIRE = "WIRE"


class CalculateCashBalanceResponseTransferSummaryTypedDict(TypedDict):
    r"""A summary of a transfer."""

    amount: NotRequired[
        Nullable[CalculateCashBalanceResponseTransferSummaryAmountTypedDict]
    ]
    r"""The amount of the transfer in USD. The value will be positive for deposits and negative for withdrawals."""
    id: NotRequired[str]
    r"""The identifier of the transfer. The value is the last part of the transfer resource name."""
    mechanism: NotRequired[CalculateCashBalanceResponseTransferSummaryMechanism]
    r"""The mechanism of the transfer."""


class CalculateCashBalanceResponseTransferSummary(BaseModel):
    r"""A summary of a transfer."""

    amount: OptionalNullable[CalculateCashBalanceResponseTransferSummaryAmount] = UNSET
    r"""The amount of the transfer in USD. The value will be positive for deposits and negative for withdrawals."""

    id: Optional[str] = None
    r"""The identifier of the transfer. The value is the last part of the transfer resource name."""

    mechanism: Annotated[
        Optional[CalculateCashBalanceResponseTransferSummaryMechanism],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""The mechanism of the transfer."""

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

        serialized = handler(self)

        m = {}

        for n, f in 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
