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

from __future__ import annotations
from enum import Enum
from gusto_embedded.types import BaseModel, Nullable, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class W4DataType(str, Enum):
    r"""The version of w4 form."""

    PRE_2020_W4 = "pre_2020_w4"
    REV_2020_W4 = "rev_2020_w4"


class EmployeeFederalTaxTypedDict(TypedDict):
    r"""Example response"""

    version: str
    r"""The current version of the object. See the [versioning guide](https://docs.gusto.com/embedded-payroll/docs/idempotency) for information on how to use this field."""
    filing_status: str
    r"""It determines which tax return form an individual will use and is an important factor in computing taxable income. One of:
    - Single
    - Married
    - Head of Household
    - Exempt from withholding
    - Married, but withhold as Single (does not apply to rev_2020_w4 form)
    """
    extra_withholding: Nullable[str]
    r"""An employee can request an additional amount to be withheld from each paycheck."""
    two_jobs: Nullable[bool]
    r"""If there are only two jobs (i.e., you and your spouse each have a job, or you have two), you can set it to true."""
    dependents_amount: Nullable[str]
    r"""A dependent is a person other than the taxpayer or spouse who entitles the taxpayer to claim a dependency exemption."""
    other_income: Nullable[str]
    r"""Other income amount."""
    deductions: Nullable[str]
    r"""Deductions other than the standard deduction to reduce withholding."""
    w4_data_type: W4DataType
    r"""The version of w4 form."""
    federal_withholding_allowance: NotRequired[float]
    r"""*does not apply to rev_2020_w4 form*

    An exemption from paying a certain amount of income tax.
    """
    additional_withholding: NotRequired[bool]
    r"""*does not apply to rev_2020_w4 form*"""


class EmployeeFederalTax(BaseModel):
    r"""Example response"""

    version: str
    r"""The current version of the object. See the [versioning guide](https://docs.gusto.com/embedded-payroll/docs/idempotency) for information on how to use this field."""

    filing_status: str
    r"""It determines which tax return form an individual will use and is an important factor in computing taxable income. One of:
    - Single
    - Married
    - Head of Household
    - Exempt from withholding
    - Married, but withhold as Single (does not apply to rev_2020_w4 form)
    """

    extra_withholding: Nullable[str]
    r"""An employee can request an additional amount to be withheld from each paycheck."""

    two_jobs: Nullable[bool]
    r"""If there are only two jobs (i.e., you and your spouse each have a job, or you have two), you can set it to true."""

    dependents_amount: Nullable[str]
    r"""A dependent is a person other than the taxpayer or spouse who entitles the taxpayer to claim a dependency exemption."""

    other_income: Nullable[str]
    r"""Other income amount."""

    deductions: Nullable[str]
    r"""Deductions other than the standard deduction to reduce withholding."""

    w4_data_type: W4DataType
    r"""The version of w4 form."""

    federal_withholding_allowance: Optional[float] = None
    r"""*does not apply to rev_2020_w4 form*

    An exemption from paying a certain amount of income tax.
    """

    additional_withholding: Optional[bool] = None
    r"""*does not apply to rev_2020_w4 form*"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["federal_withholding_allowance", "additional_withholding"]
        nullable_fields = [
            "extra_withholding",
            "two_jobs",
            "dependents_amount",
            "other_income",
            "deductions",
        ]
        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
