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

from __future__ import annotations
from enum import Enum
from gusto_app_integration.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class Name(str, Enum):
    r"""The name of the paid time off type."""

    VACATION_HOURS = "Vacation Hours"
    SICK_HOURS = "Sick Hours"
    HOLIDAY_HOURS = "Holiday Hours"


class PaidTimeOffTypedDict(TypedDict):
    r"""The representation of paid time off in Gusto."""

    name: NotRequired[Name]
    r"""The name of the paid time off type."""
    policy_name: NotRequired[str]
    r"""The name of the time off policy."""
    policy_uuid: NotRequired[str]
    r"""The UUID of the time off policy."""
    accrual_unit: NotRequired[str]
    r"""The unit the PTO type is accrued in."""
    accrual_rate: NotRequired[str]
    r"""The number of accrual units accrued per accrual period."""
    accrual_method: NotRequired[str]
    r"""The accrual method of the time off policy"""
    accrual_period: NotRequired[str]
    r"""The frequency at which the PTO type is accrued."""
    accrual_balance: NotRequired[str]
    r"""The number of accrual units accrued."""
    maximum_accrual_balance: NotRequired[Nullable[str]]
    r"""The maximum number of accrual units allowed. A null value signifies no maximum."""
    paid_at_termination: NotRequired[bool]
    r"""Whether the accrual balance is paid to the employee upon termination."""


class PaidTimeOff(BaseModel):
    r"""The representation of paid time off in Gusto."""

    name: Optional[Name] = None
    r"""The name of the paid time off type."""

    policy_name: Optional[str] = None
    r"""The name of the time off policy."""

    policy_uuid: Optional[str] = None
    r"""The UUID of the time off policy."""

    accrual_unit: Optional[str] = None
    r"""The unit the PTO type is accrued in."""

    accrual_rate: Optional[str] = None
    r"""The number of accrual units accrued per accrual period."""

    accrual_method: Optional[str] = None
    r"""The accrual method of the time off policy"""

    accrual_period: Optional[str] = None
    r"""The frequency at which the PTO type is accrued."""

    accrual_balance: Optional[str] = None
    r"""The number of accrual units accrued."""

    maximum_accrual_balance: OptionalNullable[str] = UNSET
    r"""The maximum number of accrual units allowed. A null value signifies no maximum."""

    paid_at_termination: Optional[bool] = None
    r"""Whether the accrual balance is paid to the employee upon termination."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "name",
            "policy_name",
            "policy_uuid",
            "accrual_unit",
            "accrual_rate",
            "accrual_method",
            "accrual_period",
            "accrual_balance",
            "maximum_accrual_balance",
            "paid_at_termination",
        ]
        nullable_fields = ["maximum_accrual_balance"]
        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
