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

from __future__ import annotations
from documenso_sdk import utils
from documenso_sdk.types import BaseModel, Nullable, UNSET_SENTINEL
from documenso_sdk.utils import FieldMetadata, PathParamMetadata
from enum import Enum
import pydantic
from pydantic import model_serializer
from typing import Any, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class FieldGetTemplateFieldRequestTypedDict(TypedDict):
    field_id: float


class FieldGetTemplateFieldRequest(BaseModel):
    field_id: Annotated[
        float,
        pydantic.Field(alias="fieldId"),
        FieldMetadata(path=PathParamMetadata(style="simple", explode=False)),
    ]


class FieldGetTemplateFieldTemplatesFieldsResponseIssuesTypedDict(TypedDict):
    message: str


class FieldGetTemplateFieldTemplatesFieldsResponseIssues(BaseModel):
    message: str


class FieldGetTemplateFieldTemplatesFieldsResponse500ResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldGetTemplateFieldTemplatesFieldsResponseIssues]] = None


class FieldGetTemplateFieldTemplatesFieldsResponse500ResponseBody(Exception):
    r"""Internal server error"""

    data: FieldGetTemplateFieldTemplatesFieldsResponse500ResponseBodyData

    def __init__(
        self, data: FieldGetTemplateFieldTemplatesFieldsResponse500ResponseBodyData
    ):
        self.data = data

    def __str__(self) -> str:
        return utils.marshal_json(
            self.data, FieldGetTemplateFieldTemplatesFieldsResponse500ResponseBodyData
        )


class FieldGetTemplateFieldTemplatesFieldsIssuesTypedDict(TypedDict):
    message: str


class FieldGetTemplateFieldTemplatesFieldsIssues(BaseModel):
    message: str


class FieldGetTemplateFieldTemplatesFieldsResponseResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldGetTemplateFieldTemplatesFieldsIssues]] = None


class FieldGetTemplateFieldTemplatesFieldsResponseResponseBody(Exception):
    r"""Not found"""

    data: FieldGetTemplateFieldTemplatesFieldsResponseResponseBodyData

    def __init__(
        self, data: FieldGetTemplateFieldTemplatesFieldsResponseResponseBodyData
    ):
        self.data = data

    def __str__(self) -> str:
        return utils.marshal_json(
            self.data, FieldGetTemplateFieldTemplatesFieldsResponseResponseBodyData
        )


class FieldGetTemplateFieldIssuesTypedDict(TypedDict):
    message: str


class FieldGetTemplateFieldIssues(BaseModel):
    message: str


class FieldGetTemplateFieldTemplatesFieldsResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldGetTemplateFieldIssues]] = None


class FieldGetTemplateFieldTemplatesFieldsResponseBody(Exception):
    r"""Invalid input data"""

    data: FieldGetTemplateFieldTemplatesFieldsResponseBodyData

    def __init__(self, data: FieldGetTemplateFieldTemplatesFieldsResponseBodyData):
        self.data = data

    def __str__(self) -> str:
        return utils.marshal_json(
            self.data, FieldGetTemplateFieldTemplatesFieldsResponseBodyData
        )


class FieldGetTemplateFieldType(str, Enum):
    SIGNATURE = "SIGNATURE"
    FREE_SIGNATURE = "FREE_SIGNATURE"
    INITIALS = "INITIALS"
    NAME = "NAME"
    EMAIL = "EMAIL"
    DATE = "DATE"
    TEXT = "TEXT"
    NUMBER = "NUMBER"
    RADIO = "RADIO"
    CHECKBOX = "CHECKBOX"
    DROPDOWN = "DROPDOWN"


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody9Type(
    str, Enum
):
    DROPDOWN = "dropdown"


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponseValuesTypedDict(TypedDict):
    value: str


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponseValues(BaseModel):
    value: str


class FieldGetTemplateFieldFieldMeta9TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody9Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldGetTemplateFieldFieldMetaTemplatesFieldsResponseValuesTypedDict]
    ]
    default_value: NotRequired[str]


class FieldGetTemplateFieldFieldMeta9(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody9Type

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    values: Optional[
        List[FieldGetTemplateFieldFieldMetaTemplatesFieldsResponseValues]
    ] = None

    default_value: Annotated[Optional[str], pydantic.Field(alias="defaultValue")] = None


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody8Type(
    str, Enum
):
    CHECKBOX = "checkbox"


class FieldGetTemplateFieldFieldMetaTemplatesFieldsValuesTypedDict(TypedDict):
    id: float
    checked: bool
    value: str


class FieldGetTemplateFieldFieldMetaTemplatesFieldsValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldGetTemplateFieldFieldMeta8TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody8Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldGetTemplateFieldFieldMetaTemplatesFieldsValuesTypedDict]
    ]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]


class FieldGetTemplateFieldFieldMeta8(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody8Type

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    values: Optional[List[FieldGetTemplateFieldFieldMetaTemplatesFieldsValues]] = None

    validation_rule: Annotated[
        Optional[str], pydantic.Field(alias="validationRule")
    ] = None

    validation_length: Annotated[
        Optional[float], pydantic.Field(alias="validationLength")
    ] = None


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody7Type(
    str, Enum
):
    RADIO = "radio"


class FieldGetTemplateFieldFieldMetaValuesTypedDict(TypedDict):
    id: float
    checked: bool
    value: str


class FieldGetTemplateFieldFieldMetaValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldGetTemplateFieldFieldMeta7TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody7Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[List[FieldGetTemplateFieldFieldMetaValuesTypedDict]]


class FieldGetTemplateFieldFieldMeta7(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody7Type

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    values: Optional[List[FieldGetTemplateFieldFieldMetaValues]] = None


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBodyType(
    str, Enum
):
    NUMBER = "number"


class FieldGetTemplateFieldFieldMeta6TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBodyType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    number_format: NotRequired[str]
    value: NotRequired[str]
    min_value: NotRequired[float]
    max_value: NotRequired[float]
    font_size: NotRequired[float]


class FieldGetTemplateFieldFieldMeta6(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBodyType

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    number_format: Annotated[Optional[str], pydantic.Field(alias="numberFormat")] = None

    value: Optional[str] = None

    min_value: Annotated[Optional[float], pydantic.Field(alias="minValue")] = None

    max_value: Annotated[Optional[float], pydantic.Field(alias="maxValue")] = None

    font_size: Annotated[Optional[float], pydantic.Field(alias="fontSize")] = None


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONType(
    str, Enum
):
    TEXT = "text"


class FieldGetTemplateFieldFieldMeta5TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    text: NotRequired[str]
    character_limit: NotRequired[float]
    font_size: NotRequired[float]


class FieldGetTemplateFieldFieldMeta5(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONType

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    text: Optional[str] = None

    character_limit: Annotated[
        Optional[float], pydantic.Field(alias="characterLimit")
    ] = None

    font_size: Annotated[Optional[float], pydantic.Field(alias="fontSize")] = None


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200Type(str, Enum):
    DATE = "date"


class FieldGetTemplateFieldFieldMeta4TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]


class FieldGetTemplateFieldFieldMeta4(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponse200Type

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    font_size: Annotated[Optional[float], pydantic.Field(alias="fontSize")] = None


class FieldGetTemplateFieldFieldMetaTemplatesFieldsResponseType(str, Enum):
    EMAIL = "email"


class FieldGetTemplateFieldFieldMeta3TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponseType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]


class FieldGetTemplateFieldFieldMeta3(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsResponseType

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    font_size: Annotated[Optional[float], pydantic.Field(alias="fontSize")] = None


class FieldGetTemplateFieldFieldMetaTemplatesFieldsType(str, Enum):
    NAME = "name"


class FieldGetTemplateFieldFieldMeta2TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]


class FieldGetTemplateFieldFieldMeta2(BaseModel):
    type: FieldGetTemplateFieldFieldMetaTemplatesFieldsType

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    font_size: Annotated[Optional[float], pydantic.Field(alias="fontSize")] = None


class FieldGetTemplateFieldFieldMetaType(str, Enum):
    INITIALS = "initials"


class FieldGetTemplateFieldFieldMeta1TypedDict(TypedDict):
    type: FieldGetTemplateFieldFieldMetaType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]


class FieldGetTemplateFieldFieldMeta1(BaseModel):
    type: FieldGetTemplateFieldFieldMetaType

    label: Optional[str] = None

    placeholder: Optional[str] = None

    required: Optional[bool] = None

    read_only: Annotated[Optional[bool], pydantic.Field(alias="readOnly")] = None

    font_size: Annotated[Optional[float], pydantic.Field(alias="fontSize")] = None


FieldGetTemplateFieldFieldMetaTypedDict = TypeAliasType(
    "FieldGetTemplateFieldFieldMetaTypedDict",
    Union[
        FieldGetTemplateFieldFieldMeta1TypedDict,
        FieldGetTemplateFieldFieldMeta2TypedDict,
        FieldGetTemplateFieldFieldMeta3TypedDict,
        FieldGetTemplateFieldFieldMeta4TypedDict,
        FieldGetTemplateFieldFieldMeta7TypedDict,
        FieldGetTemplateFieldFieldMeta9TypedDict,
        FieldGetTemplateFieldFieldMeta5TypedDict,
        FieldGetTemplateFieldFieldMeta8TypedDict,
        FieldGetTemplateFieldFieldMeta6TypedDict,
    ],
)


FieldGetTemplateFieldFieldMeta = TypeAliasType(
    "FieldGetTemplateFieldFieldMeta",
    Union[
        FieldGetTemplateFieldFieldMeta1,
        FieldGetTemplateFieldFieldMeta2,
        FieldGetTemplateFieldFieldMeta3,
        FieldGetTemplateFieldFieldMeta4,
        FieldGetTemplateFieldFieldMeta7,
        FieldGetTemplateFieldFieldMeta9,
        FieldGetTemplateFieldFieldMeta5,
        FieldGetTemplateFieldFieldMeta8,
        FieldGetTemplateFieldFieldMeta6,
    ],
)


class FieldGetTemplateFieldResponseBodyTypedDict(TypedDict):
    r"""Successful response"""

    type: FieldGetTemplateFieldType
    id: int
    secondary_id: str
    document_id: Nullable[int]
    template_id: Nullable[int]
    recipient_id: int
    page: float
    r"""The page number of the field on the document. Starts from 1."""
    custom_text: str
    inserted: bool
    field_meta: Nullable[FieldGetTemplateFieldFieldMetaTypedDict]
    position_x: NotRequired[Any]
    position_y: NotRequired[Any]
    width: NotRequired[Any]
    height: NotRequired[Any]


class FieldGetTemplateFieldResponseBody(BaseModel):
    r"""Successful response"""

    type: FieldGetTemplateFieldType

    id: int

    secondary_id: Annotated[str, pydantic.Field(alias="secondaryId")]

    document_id: Annotated[Nullable[int], pydantic.Field(alias="documentId")]

    template_id: Annotated[Nullable[int], pydantic.Field(alias="templateId")]

    recipient_id: Annotated[int, pydantic.Field(alias="recipientId")]

    page: float
    r"""The page number of the field on the document. Starts from 1."""

    custom_text: Annotated[str, pydantic.Field(alias="customText")]

    inserted: bool

    field_meta: Annotated[
        Nullable[FieldGetTemplateFieldFieldMeta], pydantic.Field(alias="fieldMeta")
    ]

    position_x: Annotated[Optional[Any], pydantic.Field(alias="positionX")] = None

    position_y: Annotated[Optional[Any], pydantic.Field(alias="positionY")] = None

    width: Optional[Any] = None

    height: Optional[Any] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["positionX", "positionY", "width", "height"]
        nullable_fields = ["documentId", "templateId", "fieldMeta"]
        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
