"""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,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Optional
from typing_extensions import NotRequired, TypedDict


class DocumentSignedRecipientType(str, Enum):
    r"""The type of recipient associated with the document (will be `Contractor` for Contractor Documents)"""

    COMPANY = "Company"
    EMPLOYEE = "Employee"
    CONTRACTOR = "Contractor"


class DocumentSignedTypedDict(TypedDict):
    uuid: NotRequired[str]
    r"""The UUID of the document"""
    title: NotRequired[str]
    r"""The title of the document"""
    name: NotRequired[str]
    r"""The type identifier of the document"""
    recipient_type: NotRequired[DocumentSignedRecipientType]
    r"""The type of recipient associated with the document (will be `Contractor` for Contractor Documents)"""
    recipient_uuid: NotRequired[str]
    r"""Unique identifier for the recipient associated with the document"""
    signed_at: NotRequired[Nullable[str]]
    r"""When the document was signed (will be `null` if unsigned)"""
    description: NotRequired[str]
    r"""The description of the document"""
    requires_signing: NotRequired[bool]
    r"""A boolean flag that indicates whether the document needs signing or not. Note that this value will change after the document is signed."""
    draft: NotRequired[bool]
    r"""If the document is in a draft state"""
    year: NotRequired[Nullable[int]]
    r"""The year of this document. This value is nullable and will not be present on all documents."""
    quarter: NotRequired[Nullable[int]]
    r"""The quarter of this document. This value is nullable and will not be present on all documents."""


class DocumentSigned(BaseModel):
    uuid: Optional[str] = None
    r"""The UUID of the document"""

    title: Optional[str] = None
    r"""The title of the document"""

    name: Optional[str] = None
    r"""The type identifier of the document"""

    recipient_type: Optional[DocumentSignedRecipientType] = None
    r"""The type of recipient associated with the document (will be `Contractor` for Contractor Documents)"""

    recipient_uuid: Optional[str] = None
    r"""Unique identifier for the recipient associated with the document"""

    signed_at: OptionalNullable[str] = UNSET
    r"""When the document was signed (will be `null` if unsigned)"""

    description: Optional[str] = None
    r"""The description of the document"""

    requires_signing: Optional[bool] = None
    r"""A boolean flag that indicates whether the document needs signing or not. Note that this value will change after the document is signed."""

    draft: Optional[bool] = None
    r"""If the document is in a draft state"""

    year: OptionalNullable[int] = UNSET
    r"""The year of this document. This value is nullable and will not be present on all documents."""

    quarter: OptionalNullable[int] = UNSET
    r"""The quarter of this document. This value is nullable and will not be present on all documents."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "uuid",
            "title",
            "name",
            "recipient_type",
            "recipient_uuid",
            "signed_at",
            "description",
            "requires_signing",
            "draft",
            "year",
            "quarter",
        ]
        nullable_fields = ["signed_at", "year", "quarter"]
        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
