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

from __future__ import annotations
from dataclasses import dataclass, field
from documenso_sdk.models import DocumensoError
from documenso_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from enum import Enum
import httpx
import pydantic
from pydantic import model_serializer
from typing import Any, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class FieldUpdateTemplateFieldTypeDropdownRequest1(str, Enum):
    DROPDOWN = "DROPDOWN"


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


class FieldUpdateTemplateFieldValueDropdownTypedDict(TypedDict):
    value: str


class FieldUpdateTemplateFieldValueDropdown(BaseModel):
    value: str


class FieldUpdateTemplateFieldFieldMetaDropdownRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeDropdownRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[FieldUpdateTemplateFieldValueDropdownTypedDict]]
    default_value: NotRequired[str]


class FieldUpdateTemplateFieldFieldMetaDropdownRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeDropdownRequest2

    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")] = 12

    values: Optional[List[FieldUpdateTemplateFieldValueDropdown]] = None

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


class FieldUpdateTemplateFieldFieldDropdownTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeDropdownRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaDropdownRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldDropdown(BaseModel):
    type: FieldUpdateTemplateFieldTypeDropdownRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaDropdownRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeCheckboxRequest1(str, Enum):
    CHECKBOX = "CHECKBOX"


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


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


class FieldUpdateTemplateFieldValueCheckbox(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldDirectionCheckbox(str, Enum):
    VERTICAL = "vertical"
    HORIZONTAL = "horizontal"


class FieldUpdateTemplateFieldFieldMetaCheckboxRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeCheckboxRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[FieldUpdateTemplateFieldValueCheckboxTypedDict]]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]
    direction: NotRequired[FieldUpdateTemplateFieldDirectionCheckbox]


class FieldUpdateTemplateFieldFieldMetaCheckboxRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeCheckboxRequest2

    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")] = 12

    values: Optional[List[FieldUpdateTemplateFieldValueCheckbox]] = None

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

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

    direction: Optional[FieldUpdateTemplateFieldDirectionCheckbox] = (
        FieldUpdateTemplateFieldDirectionCheckbox.VERTICAL
    )


class FieldUpdateTemplateFieldFieldCheckboxTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeCheckboxRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaCheckboxRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldCheckbox(BaseModel):
    type: FieldUpdateTemplateFieldTypeCheckboxRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaCheckboxRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeRadioRequest1(str, Enum):
    RADIO = "RADIO"


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


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


class FieldUpdateTemplateFieldValueRadio(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldDirectionRadio(str, Enum):
    VERTICAL = "vertical"
    HORIZONTAL = "horizontal"


class FieldUpdateTemplateFieldFieldMetaRadioRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeRadioRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[FieldUpdateTemplateFieldValueRadioTypedDict]]
    direction: NotRequired[FieldUpdateTemplateFieldDirectionRadio]


class FieldUpdateTemplateFieldFieldMetaRadioRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeRadioRequest2

    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")] = 12

    values: Optional[List[FieldUpdateTemplateFieldValueRadio]] = None

    direction: Optional[FieldUpdateTemplateFieldDirectionRadio] = (
        FieldUpdateTemplateFieldDirectionRadio.VERTICAL
    )


class FieldUpdateTemplateFieldFieldRadioTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeRadioRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaRadioRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldRadio(BaseModel):
    type: FieldUpdateTemplateFieldTypeRadioRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaRadioRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeNumberRequest1(str, Enum):
    NUMBER = "NUMBER"


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


class FieldUpdateTemplateFieldTextAlignNumber(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldVerticalAlignNumber(str, Enum):
    TOP = "top"
    MIDDLE = "middle"
    BOTTOM = "bottom"


class FieldUpdateTemplateFieldFieldMetaNumberRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeNumberRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    number_format: NotRequired[Nullable[str]]
    value: NotRequired[str]
    min_value: NotRequired[Nullable[float]]
    max_value: NotRequired[Nullable[float]]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignNumber]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[Nullable[FieldUpdateTemplateFieldVerticalAlignNumber]]


class FieldUpdateTemplateFieldFieldMetaNumberRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeNumberRequest2

    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")] = 12

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

    value: Optional[str] = None

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

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

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignNumber],
        pydantic.Field(alias="textAlign"),
    ] = None

    line_height: Annotated[
        OptionalNullable[float], pydantic.Field(alias="lineHeight")
    ] = UNSET

    letter_spacing: Annotated[
        OptionalNullable[float], pydantic.Field(alias="letterSpacing")
    ] = UNSET

    vertical_align: Annotated[
        OptionalNullable[FieldUpdateTemplateFieldVerticalAlignNumber],
        pydantic.Field(alias="verticalAlign"),
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "label",
            "placeholder",
            "required",
            "readOnly",
            "fontSize",
            "numberFormat",
            "value",
            "minValue",
            "maxValue",
            "textAlign",
            "lineHeight",
            "letterSpacing",
            "verticalAlign",
        ]
        nullable_fields = [
            "numberFormat",
            "minValue",
            "maxValue",
            "lineHeight",
            "letterSpacing",
            "verticalAlign",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(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


class FieldUpdateTemplateFieldFieldNumberTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeNumberRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaNumberRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldNumber(BaseModel):
    type: FieldUpdateTemplateFieldTypeNumberRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaNumberRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeTextRequest1(str, Enum):
    TEXT = "TEXT"


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


class FieldUpdateTemplateFieldTextAlignText(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldVerticalAlignText(str, Enum):
    TOP = "top"
    MIDDLE = "middle"
    BOTTOM = "bottom"


class FieldUpdateTemplateFieldFieldMetaTextRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeTextRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text: NotRequired[str]
    character_limit: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignText]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[Nullable[FieldUpdateTemplateFieldVerticalAlignText]]


class FieldUpdateTemplateFieldFieldMetaTextRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeTextRequest2

    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")] = 12

    text: Optional[str] = None

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

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignText],
        pydantic.Field(alias="textAlign"),
    ] = None

    line_height: Annotated[
        OptionalNullable[float], pydantic.Field(alias="lineHeight")
    ] = UNSET

    letter_spacing: Annotated[
        OptionalNullable[float], pydantic.Field(alias="letterSpacing")
    ] = UNSET

    vertical_align: Annotated[
        OptionalNullable[FieldUpdateTemplateFieldVerticalAlignText],
        pydantic.Field(alias="verticalAlign"),
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "label",
            "placeholder",
            "required",
            "readOnly",
            "fontSize",
            "text",
            "characterLimit",
            "textAlign",
            "lineHeight",
            "letterSpacing",
            "verticalAlign",
        ]
        nullable_fields = ["lineHeight", "letterSpacing", "verticalAlign"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(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


class FieldUpdateTemplateFieldFieldTextTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeTextRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaTextRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldText(BaseModel):
    type: FieldUpdateTemplateFieldTypeTextRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaTextRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeDateRequest1(str, Enum):
    DATE = "DATE"


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


class FieldUpdateTemplateFieldTextAlignDate(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaDateRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeDateRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignDate]


class FieldUpdateTemplateFieldFieldMetaDateRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeDateRequest2

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignDate],
        pydantic.Field(alias="textAlign"),
    ] = None


class FieldUpdateTemplateFieldFieldDateTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeDateRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaDateRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldDate(BaseModel):
    type: FieldUpdateTemplateFieldTypeDateRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaDateRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeEmailRequest1(str, Enum):
    EMAIL = "EMAIL"


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


class FieldUpdateTemplateFieldTextAlignEmail(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaEmailRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeEmailRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignEmail]


class FieldUpdateTemplateFieldFieldMetaEmailRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeEmailRequest2

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignEmail],
        pydantic.Field(alias="textAlign"),
    ] = None


class FieldUpdateTemplateFieldFieldEmailTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeEmailRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaEmailRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldEmail(BaseModel):
    type: FieldUpdateTemplateFieldTypeEmailRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaEmailRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeNameRequest1(str, Enum):
    NAME = "NAME"


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


class FieldUpdateTemplateFieldTextAlignName(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaNameRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeNameRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignName]


class FieldUpdateTemplateFieldFieldMetaNameRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeNameRequest2

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignName],
        pydantic.Field(alias="textAlign"),
    ] = None


class FieldUpdateTemplateFieldFieldNameTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeNameRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaNameRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldName(BaseModel):
    type: FieldUpdateTemplateFieldTypeNameRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaNameRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeInitialsRequest1(str, Enum):
    INITIALS = "INITIALS"


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


class FieldUpdateTemplateFieldTextAlignInitials(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaInitialsRequestTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeInitialsRequest2
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignInitials]


class FieldUpdateTemplateFieldFieldMetaInitialsRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeInitialsRequest2

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignInitials],
        pydantic.Field(alias="textAlign"),
    ] = None


class FieldUpdateTemplateFieldFieldInitialsTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeInitialsRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaInitialsRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldInitials(BaseModel):
    type: FieldUpdateTemplateFieldTypeInitialsRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaInitialsRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeFreeSignature(str, Enum):
    FREE_SIGNATURE = "FREE_SIGNATURE"


class FieldUpdateTemplateFieldFieldFreeSignatureTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeFreeSignature
    id: float
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldFreeSignature(BaseModel):
    type: FieldUpdateTemplateFieldTypeFreeSignature

    id: float

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


class FieldUpdateTemplateFieldTypeSignatureRequest1(str, Enum):
    SIGNATURE = "SIGNATURE"


class FieldUpdateTemplateFieldTypeSignatureRequest2(str, Enum):
    SIGNATURE = "signature"


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


class FieldUpdateTemplateFieldFieldMetaSignatureRequest(BaseModel):
    type: FieldUpdateTemplateFieldTypeSignatureRequest2

    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")] = 12


class FieldUpdateTemplateFieldFieldSignatureTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldTypeSignatureRequest1
    id: float
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldMetaSignatureRequestTypedDict]
    page_number: NotRequired[float]
    page_x: NotRequired[float]
    page_y: NotRequired[float]
    width: NotRequired[float]
    height: NotRequired[float]


class FieldUpdateTemplateFieldFieldSignature(BaseModel):
    type: FieldUpdateTemplateFieldTypeSignatureRequest1

    id: float

    field_meta: Annotated[
        Optional[FieldUpdateTemplateFieldFieldMetaSignatureRequest],
        pydantic.Field(alias="fieldMeta"),
    ] = None

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

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

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

    width: Optional[float] = None

    height: Optional[float] = None


FieldUpdateTemplateFieldFieldUnionTypedDict = TypeAliasType(
    "FieldUpdateTemplateFieldFieldUnionTypedDict",
    Union[
        FieldUpdateTemplateFieldFieldFreeSignatureTypedDict,
        FieldUpdateTemplateFieldFieldSignatureTypedDict,
        FieldUpdateTemplateFieldFieldInitialsTypedDict,
        FieldUpdateTemplateFieldFieldNameTypedDict,
        FieldUpdateTemplateFieldFieldEmailTypedDict,
        FieldUpdateTemplateFieldFieldDateTypedDict,
        FieldUpdateTemplateFieldFieldTextTypedDict,
        FieldUpdateTemplateFieldFieldNumberTypedDict,
        FieldUpdateTemplateFieldFieldRadioTypedDict,
        FieldUpdateTemplateFieldFieldCheckboxTypedDict,
        FieldUpdateTemplateFieldFieldDropdownTypedDict,
    ],
)


FieldUpdateTemplateFieldFieldUnion = TypeAliasType(
    "FieldUpdateTemplateFieldFieldUnion",
    Union[
        FieldUpdateTemplateFieldFieldFreeSignature,
        FieldUpdateTemplateFieldFieldSignature,
        FieldUpdateTemplateFieldFieldInitials,
        FieldUpdateTemplateFieldFieldName,
        FieldUpdateTemplateFieldFieldEmail,
        FieldUpdateTemplateFieldFieldDate,
        FieldUpdateTemplateFieldFieldText,
        FieldUpdateTemplateFieldFieldNumber,
        FieldUpdateTemplateFieldFieldRadio,
        FieldUpdateTemplateFieldFieldCheckbox,
        FieldUpdateTemplateFieldFieldDropdown,
    ],
)


class FieldUpdateTemplateFieldRequestTypedDict(TypedDict):
    template_id: float
    field: FieldUpdateTemplateFieldFieldUnionTypedDict


class FieldUpdateTemplateFieldRequest(BaseModel):
    template_id: Annotated[float, pydantic.Field(alias="templateId")]

    field: FieldUpdateTemplateFieldFieldUnion


class FieldUpdateTemplateFieldInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class FieldUpdateTemplateFieldInternalServerErrorIssue(BaseModel):
    message: str


class FieldUpdateTemplateFieldInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateTemplateFieldInternalServerErrorIssue]] = None


@dataclass(unsafe_hash=True)
class FieldUpdateTemplateFieldInternalServerError(DocumensoError):
    r"""Internal server error"""

    data: FieldUpdateTemplateFieldInternalServerErrorData = field(hash=False)

    def __init__(
        self,
        data: FieldUpdateTemplateFieldInternalServerErrorData,
        raw_response: httpx.Response,
        body: Optional[str] = None,
    ):
        fallback = body or raw_response.text
        message = str(data.message) or fallback
        super().__init__(message, raw_response, body)
        object.__setattr__(self, "data", data)


class FieldUpdateTemplateFieldForbiddenIssueTypedDict(TypedDict):
    message: str


class FieldUpdateTemplateFieldForbiddenIssue(BaseModel):
    message: str


class FieldUpdateTemplateFieldForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateTemplateFieldForbiddenIssue]] = None


@dataclass(unsafe_hash=True)
class FieldUpdateTemplateFieldForbiddenError(DocumensoError):
    r"""Insufficient access"""

    data: FieldUpdateTemplateFieldForbiddenErrorData = field(hash=False)

    def __init__(
        self,
        data: FieldUpdateTemplateFieldForbiddenErrorData,
        raw_response: httpx.Response,
        body: Optional[str] = None,
    ):
        fallback = body or raw_response.text
        message = str(data.message) or fallback
        super().__init__(message, raw_response, body)
        object.__setattr__(self, "data", data)


class FieldUpdateTemplateFieldUnauthorizedIssueTypedDict(TypedDict):
    message: str


class FieldUpdateTemplateFieldUnauthorizedIssue(BaseModel):
    message: str


class FieldUpdateTemplateFieldUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateTemplateFieldUnauthorizedIssue]] = None


@dataclass(unsafe_hash=True)
class FieldUpdateTemplateFieldUnauthorizedError(DocumensoError):
    r"""Authorization not provided"""

    data: FieldUpdateTemplateFieldUnauthorizedErrorData = field(hash=False)

    def __init__(
        self,
        data: FieldUpdateTemplateFieldUnauthorizedErrorData,
        raw_response: httpx.Response,
        body: Optional[str] = None,
    ):
        fallback = body or raw_response.text
        message = str(data.message) or fallback
        super().__init__(message, raw_response, body)
        object.__setattr__(self, "data", data)


class FieldUpdateTemplateFieldBadRequestIssueTypedDict(TypedDict):
    message: str


class FieldUpdateTemplateFieldBadRequestIssue(BaseModel):
    message: str


class FieldUpdateTemplateFieldBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateTemplateFieldBadRequestIssue]] = None


@dataclass(unsafe_hash=True)
class FieldUpdateTemplateFieldBadRequestError(DocumensoError):
    r"""Invalid input data"""

    data: FieldUpdateTemplateFieldBadRequestErrorData = field(hash=False)

    def __init__(
        self,
        data: FieldUpdateTemplateFieldBadRequestErrorData,
        raw_response: httpx.Response,
        body: Optional[str] = None,
    ):
        fallback = body or raw_response.text
        message = str(data.message) or fallback
        super().__init__(message, raw_response, body)
        object.__setattr__(self, "data", data)


class FieldUpdateTemplateFieldTypeResponse(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 FieldUpdateTemplateFieldFieldMetaTypeDropdown(str, Enum):
    DROPDOWN = "dropdown"


class FieldUpdateTemplateFieldValueResponse3TypedDict(TypedDict):
    value: str


class FieldUpdateTemplateFieldValueResponse3(BaseModel):
    value: str


class FieldUpdateTemplateFieldFieldMetaDropdownResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeDropdown
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[FieldUpdateTemplateFieldValueResponse3TypedDict]]
    default_value: NotRequired[str]


class FieldUpdateTemplateFieldFieldMetaDropdownResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeDropdown

    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")] = 12

    values: Optional[List[FieldUpdateTemplateFieldValueResponse3]] = None

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


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


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


class FieldUpdateTemplateFieldValueResponse2(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldDirectionResponse2(str, Enum):
    VERTICAL = "vertical"
    HORIZONTAL = "horizontal"


class FieldUpdateTemplateFieldFieldMetaCheckboxResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeCheckbox
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[FieldUpdateTemplateFieldValueResponse2TypedDict]]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]
    direction: NotRequired[FieldUpdateTemplateFieldDirectionResponse2]


class FieldUpdateTemplateFieldFieldMetaCheckboxResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeCheckbox

    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")] = 12

    values: Optional[List[FieldUpdateTemplateFieldValueResponse2]] = None

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

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

    direction: Optional[FieldUpdateTemplateFieldDirectionResponse2] = (
        FieldUpdateTemplateFieldDirectionResponse2.VERTICAL
    )


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


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


class FieldUpdateTemplateFieldValueResponse1(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldDirectionResponse1(str, Enum):
    VERTICAL = "vertical"
    HORIZONTAL = "horizontal"


class FieldUpdateTemplateFieldFieldMetaRadioResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeRadio
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[FieldUpdateTemplateFieldValueResponse1TypedDict]]
    direction: NotRequired[FieldUpdateTemplateFieldDirectionResponse1]


class FieldUpdateTemplateFieldFieldMetaRadioResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeRadio

    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")] = 12

    values: Optional[List[FieldUpdateTemplateFieldValueResponse1]] = None

    direction: Optional[FieldUpdateTemplateFieldDirectionResponse1] = (
        FieldUpdateTemplateFieldDirectionResponse1.VERTICAL
    )


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


class FieldUpdateTemplateFieldTextAlignResponse6(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldVerticalAlignResponse2(str, Enum):
    TOP = "top"
    MIDDLE = "middle"
    BOTTOM = "bottom"


class FieldUpdateTemplateFieldFieldMetaNumberResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeNumber
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    number_format: NotRequired[Nullable[str]]
    value: NotRequired[str]
    min_value: NotRequired[Nullable[float]]
    max_value: NotRequired[Nullable[float]]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignResponse6]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[
        Nullable[FieldUpdateTemplateFieldVerticalAlignResponse2]
    ]


class FieldUpdateTemplateFieldFieldMetaNumberResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeNumber

    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")] = 12

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

    value: Optional[str] = None

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

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

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignResponse6],
        pydantic.Field(alias="textAlign"),
    ] = None

    line_height: Annotated[
        OptionalNullable[float], pydantic.Field(alias="lineHeight")
    ] = UNSET

    letter_spacing: Annotated[
        OptionalNullable[float], pydantic.Field(alias="letterSpacing")
    ] = UNSET

    vertical_align: Annotated[
        OptionalNullable[FieldUpdateTemplateFieldVerticalAlignResponse2],
        pydantic.Field(alias="verticalAlign"),
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "label",
            "placeholder",
            "required",
            "readOnly",
            "fontSize",
            "numberFormat",
            "value",
            "minValue",
            "maxValue",
            "textAlign",
            "lineHeight",
            "letterSpacing",
            "verticalAlign",
        ]
        nullable_fields = [
            "numberFormat",
            "minValue",
            "maxValue",
            "lineHeight",
            "letterSpacing",
            "verticalAlign",
        ]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(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


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


class FieldUpdateTemplateFieldTextAlignResponse5(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldVerticalAlignResponse1(str, Enum):
    TOP = "top"
    MIDDLE = "middle"
    BOTTOM = "bottom"


class FieldUpdateTemplateFieldFieldMetaTextResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeText
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text: NotRequired[str]
    character_limit: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignResponse5]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[
        Nullable[FieldUpdateTemplateFieldVerticalAlignResponse1]
    ]


class FieldUpdateTemplateFieldFieldMetaTextResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeText

    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")] = 12

    text: Optional[str] = None

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

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignResponse5],
        pydantic.Field(alias="textAlign"),
    ] = None

    line_height: Annotated[
        OptionalNullable[float], pydantic.Field(alias="lineHeight")
    ] = UNSET

    letter_spacing: Annotated[
        OptionalNullable[float], pydantic.Field(alias="letterSpacing")
    ] = UNSET

    vertical_align: Annotated[
        OptionalNullable[FieldUpdateTemplateFieldVerticalAlignResponse1],
        pydantic.Field(alias="verticalAlign"),
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "label",
            "placeholder",
            "required",
            "readOnly",
            "fontSize",
            "text",
            "characterLimit",
            "textAlign",
            "lineHeight",
            "letterSpacing",
            "verticalAlign",
        ]
        nullable_fields = ["lineHeight", "letterSpacing", "verticalAlign"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(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


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


class FieldUpdateTemplateFieldTextAlignResponse4(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaDateResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeDate
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignResponse4]


class FieldUpdateTemplateFieldFieldMetaDateResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeDate

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignResponse4],
        pydantic.Field(alias="textAlign"),
    ] = None


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


class FieldUpdateTemplateFieldTextAlignResponse3(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaEmailResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeEmail
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignResponse3]


class FieldUpdateTemplateFieldFieldMetaEmailResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeEmail

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignResponse3],
        pydantic.Field(alias="textAlign"),
    ] = None


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


class FieldUpdateTemplateFieldTextAlignResponse2(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaNameResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeName
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignResponse2]


class FieldUpdateTemplateFieldFieldMetaNameResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeName

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignResponse2],
        pydantic.Field(alias="textAlign"),
    ] = None


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


class FieldUpdateTemplateFieldTextAlignResponse1(str, Enum):
    LEFT = "left"
    CENTER = "center"
    RIGHT = "right"


class FieldUpdateTemplateFieldFieldMetaInitialsResponseTypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTypeInitials
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[FieldUpdateTemplateFieldTextAlignResponse1]


class FieldUpdateTemplateFieldFieldMetaInitialsResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeInitials

    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")] = 12

    text_align: Annotated[
        Optional[FieldUpdateTemplateFieldTextAlignResponse1],
        pydantic.Field(alias="textAlign"),
    ] = None


class FieldUpdateTemplateFieldFieldMetaTypeSignature(str, Enum):
    SIGNATURE = "signature"


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


class FieldUpdateTemplateFieldFieldMetaSignatureResponse(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTypeSignature

    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")] = 12


FieldUpdateTemplateFieldFieldMetaUnionTypedDict = TypeAliasType(
    "FieldUpdateTemplateFieldFieldMetaUnionTypedDict",
    Union[
        FieldUpdateTemplateFieldFieldMetaSignatureResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaInitialsResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaNameResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaEmailResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaDateResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaRadioResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaDropdownResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaCheckboxResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaTextResponseTypedDict,
        FieldUpdateTemplateFieldFieldMetaNumberResponseTypedDict,
    ],
)


FieldUpdateTemplateFieldFieldMetaUnion = TypeAliasType(
    "FieldUpdateTemplateFieldFieldMetaUnion",
    Union[
        FieldUpdateTemplateFieldFieldMetaSignatureResponse,
        FieldUpdateTemplateFieldFieldMetaInitialsResponse,
        FieldUpdateTemplateFieldFieldMetaNameResponse,
        FieldUpdateTemplateFieldFieldMetaEmailResponse,
        FieldUpdateTemplateFieldFieldMetaDateResponse,
        FieldUpdateTemplateFieldFieldMetaRadioResponse,
        FieldUpdateTemplateFieldFieldMetaDropdownResponse,
        FieldUpdateTemplateFieldFieldMetaCheckboxResponse,
        FieldUpdateTemplateFieldFieldMetaTextResponse,
        FieldUpdateTemplateFieldFieldMetaNumberResponse,
    ],
)


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

    envelope_id: str
    envelope_item_id: str
    type: FieldUpdateTemplateFieldTypeResponse
    id: float
    secondary_id: str
    recipient_id: float
    page: float
    position_x: Any
    position_y: Any
    width: Any
    height: Any
    custom_text: str
    inserted: bool
    field_meta: Nullable[FieldUpdateTemplateFieldFieldMetaUnionTypedDict]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

    envelope_id: Annotated[str, pydantic.Field(alias="envelopeId")]

    envelope_item_id: Annotated[str, pydantic.Field(alias="envelopeItemId")]

    type: FieldUpdateTemplateFieldTypeResponse

    id: float

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

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

    page: float

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

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

    width: Any

    height: Any

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

    inserted: bool

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

    document_id: Annotated[
        OptionalNullable[float], pydantic.Field(alias="documentId")
    ] = UNSET

    template_id: Annotated[
        OptionalNullable[float], pydantic.Field(alias="templateId")
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["documentId", "templateId"]
        nullable_fields = ["fieldMeta", "documentId", "templateId"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in type(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
