"""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 FeeAmountTypedDict(TypedDict):
    r"""Monetary amount associated with the fee"""

    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 FeeAmount(BaseModel):
    r"""Monetary amount associated with the fee"""

    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 FeeType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The type of fee being assessed"""

    FEE_TYPE_UNSPECIFIED = "FEE_TYPE_UNSPECIFIED"
    CLIENT_CLEARING = "CLIENT_CLEARING"
    LIQUIDITY = "LIQUIDITY"
    GENERAL_PURPOSE = "GENERAL_PURPOSE"
    COMMISSION = "COMMISSION"
    ORF = "ORF"
    TAF = "TAF"
    SEC = "SEC"
    ACCOUNT_CLOSING = "ACCOUNT_CLOSING"
    ACCOUNT_IRA = "ACCOUNT_IRA"
    ACH_RETURN = "ACH_RETURN"
    ADVISORY = "ADVISORY"
    CHECK_FEE = "CHECK_FEE"
    EXCHANGE = "EXCHANGE"
    MANAGEMENT = "MANAGEMENT"
    OVERNIGHT = "OVERNIGHT"
    PLATFORM = "PLATFORM"
    STATEMENT = "STATEMENT"
    STOP_PAYMENT = "STOP_PAYMENT"
    WIRE_FEE = "WIRE_FEE"
    INACTIVITY = "INACTIVITY"
    AMA_SERVICE = "AMA_SERVICE"
    NOTICE_OF_CHANGE = "NOTICE_OF_CHANGE"
    ACCOUNT_TRANSFER = "ACCOUNT_TRANSFER"
    AGENCY_PROCESSING = "AGENCY_PROCESSING"
    RTP_FEE = "RTP_FEE"
    DOMESTIC_WIRE_DEPOSIT_FEE = "DOMESTIC_WIRE_DEPOSIT_FEE"
    DOMESTIC_WIRE_WITHDRAWAL_FEE = "DOMESTIC_WIRE_WITHDRAWAL_FEE"
    INTERNATIONAL_WIRE_DEPOSIT_FEE = "INTERNATIONAL_WIRE_DEPOSIT_FEE"
    INTERNATIONAL_WIRE_WITHDRAWAL_FEE = "INTERNATIONAL_WIRE_WITHDRAWAL_FEE"
    BROKER_FEE = "BROKER_FEE"


class FeeTypedDict(TypedDict):
    amount: NotRequired[Nullable[FeeAmountTypedDict]]
    r"""Monetary amount associated with the fee"""
    type: NotRequired[FeeType]
    r"""The type of fee being assessed"""


class Fee(BaseModel):
    amount: OptionalNullable[FeeAmount] = UNSET
    r"""Monetary amount associated with the fee"""

    type: Annotated[Optional[FeeType], PlainValidator(validate_open_enum(False))] = None
    r"""The type of fee being assessed"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["amount", "type"]
        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
