"""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 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 FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11Type(str, Enum):
    DROPDOWN = "DROPDOWN"


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


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestValuesTypedDict(TypedDict):
    value: str


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestValues(BaseModel):
    value: str


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11FieldMetaType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateTemplateFieldFieldTemplatesFieldsRequestValuesTypedDict]
    ]
    default_value: NotRequired[str]


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11FieldMeta(
    BaseModel
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11FieldMetaType

    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[FieldUpdateTemplateFieldFieldTemplatesFieldsRequestValues]
    ] = None

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


class FieldUpdateTemplateFieldField11TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11FieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField11(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody11Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


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


class FieldUpdateTemplateFieldFieldTemplatesFieldsValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody10FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody10FieldMetaType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateTemplateFieldFieldTemplatesFieldsValuesTypedDict]
    ]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody10FieldMeta(
    BaseModel
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody10FieldMetaType

    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[FieldUpdateTemplateFieldFieldTemplatesFieldsValues]] = None

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

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


class FieldUpdateTemplateFieldField10TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody10Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody10FieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField10(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody10Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


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


class FieldUpdateTemplateFieldFieldValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody9FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody9FieldMetaType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[List[FieldUpdateTemplateFieldFieldValuesTypedDict]]


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody9FieldMeta(
    BaseModel
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody9FieldMetaType

    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[FieldUpdateTemplateFieldFieldValues]] = None


class FieldUpdateTemplateFieldField9TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody9Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody9FieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField9(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody9Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody8FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody8FieldMetaType
    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 FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody8FieldMeta(
    BaseModel
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody8FieldMetaType

    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 FieldUpdateTemplateFieldField8TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody8Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody8FieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField8(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody8Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody7FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody7FieldMetaType
    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 FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody7FieldMeta(
    BaseModel
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody7FieldMetaType

    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 FieldUpdateTemplateFieldField7TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody7Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody7FieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField7(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody7Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


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


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBodyFieldMeta(
    BaseModel
):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody6FieldMetaType

    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 FieldUpdateTemplateFieldField6TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody6Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBodyFieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField6(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody6Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


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


class FieldUpdateTemplateFieldFieldTemplatesFieldsRequestFieldMeta(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody5FieldMetaType

    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 FieldUpdateTemplateFieldField5TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody5Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsRequestFieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField5(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody5Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


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


class FieldUpdateTemplateFieldFieldTemplatesFieldsFieldMeta(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody4FieldMetaType

    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 FieldUpdateTemplateFieldField4TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody4Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateTemplateFieldFieldTemplatesFieldsFieldMetaTypedDict
    ]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField4(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBody4Type

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


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


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


class FieldUpdateTemplateFieldFieldFieldMeta(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestRequestBodyType

    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 FieldUpdateTemplateFieldField3TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestType
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[FieldUpdateTemplateFieldFieldFieldMetaTypedDict]
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField3(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsRequestType

    id: float
    r"""The ID of the field to update."""

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

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


class FieldUpdateTemplateFieldField2TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsType
    id: float
    r"""The ID of the field to update."""
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField2(BaseModel):
    type: FieldUpdateTemplateFieldFieldTemplatesFieldsType

    id: float
    r"""The ID of the field to update."""

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


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


class FieldUpdateTemplateFieldField1TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldType
    id: float
    r"""The ID of the field to update."""
    page_number: NotRequired[float]
    r"""The page number the field will be on."""
    page_x: NotRequired[float]
    r"""The X coordinate of where the field will be placed."""
    page_y: NotRequired[float]
    r"""The Y coordinate of where the field will be placed."""
    width: NotRequired[float]
    r"""The width of the field."""
    height: NotRequired[float]
    r"""The height of the field."""


class FieldUpdateTemplateFieldField1(BaseModel):
    type: FieldUpdateTemplateFieldFieldType

    id: float
    r"""The ID of the field to update."""

    page_number: Annotated[Optional[float], pydantic.Field(alias="pageNumber")] = None
    r"""The page number the field will be on."""

    page_x: Annotated[Optional[float], pydantic.Field(alias="pageX")] = None
    r"""The X coordinate of where the field will be placed."""

    page_y: Annotated[Optional[float], pydantic.Field(alias="pageY")] = None
    r"""The Y coordinate of where the field will be placed."""

    width: Optional[float] = None
    r"""The width of the field."""

    height: Optional[float] = None
    r"""The height of the field."""


FieldUpdateTemplateFieldFieldTypedDict = TypeAliasType(
    "FieldUpdateTemplateFieldFieldTypedDict",
    Union[
        FieldUpdateTemplateFieldField1TypedDict,
        FieldUpdateTemplateFieldField2TypedDict,
        FieldUpdateTemplateFieldField3TypedDict,
        FieldUpdateTemplateFieldField4TypedDict,
        FieldUpdateTemplateFieldField5TypedDict,
        FieldUpdateTemplateFieldField6TypedDict,
        FieldUpdateTemplateFieldField7TypedDict,
        FieldUpdateTemplateFieldField8TypedDict,
        FieldUpdateTemplateFieldField9TypedDict,
        FieldUpdateTemplateFieldField10TypedDict,
        FieldUpdateTemplateFieldField11TypedDict,
    ],
)


FieldUpdateTemplateFieldField = TypeAliasType(
    "FieldUpdateTemplateFieldField",
    Union[
        FieldUpdateTemplateFieldField1,
        FieldUpdateTemplateFieldField2,
        FieldUpdateTemplateFieldField3,
        FieldUpdateTemplateFieldField4,
        FieldUpdateTemplateFieldField5,
        FieldUpdateTemplateFieldField6,
        FieldUpdateTemplateFieldField7,
        FieldUpdateTemplateFieldField8,
        FieldUpdateTemplateFieldField9,
        FieldUpdateTemplateFieldField10,
        FieldUpdateTemplateFieldField11,
    ],
)


class FieldUpdateTemplateFieldRequestBodyTypedDict(TypedDict):
    template_id: float
    field: FieldUpdateTemplateFieldFieldTypedDict


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

    field: FieldUpdateTemplateFieldField


class FieldUpdateTemplateFieldTemplatesFieldsIssuesTypedDict(TypedDict):
    message: str


class FieldUpdateTemplateFieldTemplatesFieldsIssues(BaseModel):
    message: str


class FieldUpdateTemplateFieldTemplatesFieldsResponseResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateTemplateFieldTemplatesFieldsIssues]] = None


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

    data: FieldUpdateTemplateFieldTemplatesFieldsResponseResponseBodyData

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

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


class FieldUpdateTemplateFieldIssuesTypedDict(TypedDict):
    message: str


class FieldUpdateTemplateFieldIssues(BaseModel):
    message: str


class FieldUpdateTemplateFieldTemplatesFieldsResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateTemplateFieldIssues]] = None


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

    data: FieldUpdateTemplateFieldTemplatesFieldsResponseBodyData

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

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


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


class FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponseValuesTypedDict(
    TypedDict
):
    value: str


class FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponseValues(BaseModel):
    value: str


class FieldUpdateTemplateFieldFieldMeta9TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody9Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponseValuesTypedDict]
    ]
    default_value: NotRequired[str]


class FieldUpdateTemplateFieldFieldMeta9(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody9Type

    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[FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponseValues]
    ] = None

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


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


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


class FieldUpdateTemplateFieldFieldMetaTemplatesFieldsValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldFieldMeta8TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody8Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateTemplateFieldFieldMetaTemplatesFieldsValuesTypedDict]
    ]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]


class FieldUpdateTemplateFieldFieldMeta8(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody8Type

    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[FieldUpdateTemplateFieldFieldMetaTemplatesFieldsValues]] = (
        None
    )

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

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


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


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


class FieldUpdateTemplateFieldFieldMetaValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateTemplateFieldFieldMeta7TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody7Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[List[FieldUpdateTemplateFieldFieldMetaValuesTypedDict]]


class FieldUpdateTemplateFieldFieldMeta7(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBody7Type

    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[FieldUpdateTemplateFieldFieldMetaValues]] = None


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


class FieldUpdateTemplateFieldFieldMeta6TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBodyType
    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 FieldUpdateTemplateFieldFieldMeta6(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONResponseBodyType

    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 FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONType(
    str, Enum
):
    TEXT = "text"


class FieldUpdateTemplateFieldFieldMeta5TypedDict(TypedDict):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONType
    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 FieldUpdateTemplateFieldFieldMeta5(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200ApplicationJSONType

    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 FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200Type(str, Enum):
    DATE = "date"


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


class FieldUpdateTemplateFieldFieldMeta4(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponse200Type

    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 FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponseType(str, Enum):
    EMAIL = "email"


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


class FieldUpdateTemplateFieldFieldMeta3(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsResponseType

    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 FieldUpdateTemplateFieldFieldMetaTemplatesFieldsType(str, Enum):
    NAME = "name"


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


class FieldUpdateTemplateFieldFieldMeta2(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaTemplatesFieldsType

    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 FieldUpdateTemplateFieldFieldMetaType(str, Enum):
    INITIALS = "initials"


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


class FieldUpdateTemplateFieldFieldMeta1(BaseModel):
    type: FieldUpdateTemplateFieldFieldMetaType

    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


FieldUpdateTemplateFieldFieldMetaTypedDict = TypeAliasType(
    "FieldUpdateTemplateFieldFieldMetaTypedDict",
    Union[
        FieldUpdateTemplateFieldFieldMeta1TypedDict,
        FieldUpdateTemplateFieldFieldMeta2TypedDict,
        FieldUpdateTemplateFieldFieldMeta3TypedDict,
        FieldUpdateTemplateFieldFieldMeta4TypedDict,
        FieldUpdateTemplateFieldFieldMeta7TypedDict,
        FieldUpdateTemplateFieldFieldMeta9TypedDict,
        FieldUpdateTemplateFieldFieldMeta5TypedDict,
        FieldUpdateTemplateFieldFieldMeta8TypedDict,
        FieldUpdateTemplateFieldFieldMeta6TypedDict,
    ],
)


FieldUpdateTemplateFieldFieldMeta = TypeAliasType(
    "FieldUpdateTemplateFieldFieldMeta",
    Union[
        FieldUpdateTemplateFieldFieldMeta1,
        FieldUpdateTemplateFieldFieldMeta2,
        FieldUpdateTemplateFieldFieldMeta3,
        FieldUpdateTemplateFieldFieldMeta4,
        FieldUpdateTemplateFieldFieldMeta7,
        FieldUpdateTemplateFieldFieldMeta9,
        FieldUpdateTemplateFieldFieldMeta5,
        FieldUpdateTemplateFieldFieldMeta8,
        FieldUpdateTemplateFieldFieldMeta6,
    ],
)


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

    type: FieldUpdateTemplateFieldType
    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[FieldUpdateTemplateFieldFieldMetaTypedDict]
    position_x: NotRequired[Any]
    position_y: NotRequired[Any]
    width: NotRequired[Any]
    height: NotRequired[Any]


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

    type: FieldUpdateTemplateFieldType

    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[FieldUpdateTemplateFieldFieldMeta], 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
