"""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 RateTypedDict(TypedDict):
    r"""The rate at which monies were withheld, expressed as a value between 0-1"""

    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 Rate(BaseModel):
    r"""The rate at which monies were withheld, expressed as a value between 0-1"""

    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 WithholdingDataState(str, Enum, metaclass=utils.OpenEnumMeta):
    WITHHOLDING_STATE_UNSPECIFIED = "WITHHOLDING_STATE_UNSPECIFIED"
    CA = "CA"
    ME = "ME"
    VT = "VT"
    AL = "AL"
    AK = "AK"
    AZ = "AZ"
    AR = "AR"
    CO = "CO"
    CT = "CT"
    DE = "DE"
    FL = "FL"
    GA = "GA"
    HI = "HI"
    ID = "ID"
    IL = "IL"
    IN = "IN"
    IA = "IA"
    KS = "KS"
    KY = "KY"
    LA = "LA"
    MD = "MD"
    MA = "MA"
    MI = "MI"
    MN = "MN"
    MS = "MS"
    MO = "MO"
    MT = "MT"
    NE = "NE"
    NV = "NV"
    NH = "NH"
    NJ = "NJ"
    NM = "NM"
    NY = "NY"
    NC = "NC"
    ND = "ND"
    OH = "OH"
    OK = "OK"
    OR = "OR"
    PA = "PA"
    RI = "RI"
    SC = "SC"
    SD = "SD"
    TN = "TN"
    TX = "TX"
    UT = "UT"
    VA = "VA"
    WA = "WA"
    WV = "WV"
    WI = "WI"
    WY = "WY"


class WithholdingDataType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Provides more detail on the type of the withholding (Federal, State, etc.)"""

    WITHHOLDING_TYPE_UNSPECIFIED = "WITHHOLDING_TYPE_UNSPECIFIED"
    FEDERAL = "FEDERAL"
    STATE = "STATE"
    FOREIGN_SECURITY = "FOREIGN_SECURITY"
    FEDERAL_IRA = "FEDERAL_IRA"
    STATE_IRA = "STATE_IRA"
    NON_RESIDENT_ALIEN = "NON_RESIDENT_ALIEN"


class WithholdingDataTypedDict(TypedDict):
    rate: NotRequired[Nullable[RateTypedDict]]
    r"""The rate at which monies were withheld, expressed as a value between 0-1"""
    region_code: NotRequired[str]
    r"""2-Letter alpha code for the names of countries, dependent territories, and special areas of geographical interest. Complies with ISO-3166 Alpha-2 Codes"""
    state: NotRequired[WithholdingDataState]
    tax_year: NotRequired[int]
    r"""The tax year associated with the withholding"""
    type: NotRequired[WithholdingDataType]
    r"""Provides more detail on the type of the withholding (Federal, State, etc.)"""


class WithholdingData(BaseModel):
    rate: OptionalNullable[Rate] = UNSET
    r"""The rate at which monies were withheld, expressed as a value between 0-1"""

    region_code: Optional[str] = None
    r"""2-Letter alpha code for the names of countries, dependent territories, and special areas of geographical interest. Complies with ISO-3166 Alpha-2 Codes"""

    state: Annotated[
        Optional[WithholdingDataState], PlainValidator(validate_open_enum(False))
    ] = None

    tax_year: Optional[int] = None
    r"""The tax year associated with the withholding"""

    type: Annotated[
        Optional[WithholdingDataType], PlainValidator(validate_open_enum(False))
    ] = None
    r"""Provides more detail on the type of the withholding (Federal, State, etc.)"""

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