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


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


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestValuesTypedDict(TypedDict):
    value: str


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestValues(BaseModel):
    value: str


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11FieldMetaType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateDocumentFieldFieldDocumentsFieldsRequestValuesTypedDict]
    ]
    default_value: NotRequired[str]


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11FieldMeta(
    BaseModel
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11FieldMetaType

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

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


class FieldUpdateDocumentFieldField11TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11FieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField11(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11Type

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

    field_meta: Annotated[
        Optional[
            FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody11FieldMeta
        ],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10Type(str, Enum):
    CHECKBOX = "CHECKBOX"


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


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


class FieldUpdateDocumentFieldFieldDocumentsFieldsValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10FieldMetaType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateDocumentFieldFieldDocumentsFieldsValuesTypedDict]
    ]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10FieldMeta(
    BaseModel
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10FieldMetaType

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

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

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


class FieldUpdateDocumentFieldField10TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10FieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField10(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10Type

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

    field_meta: Annotated[
        Optional[
            FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody10FieldMeta
        ],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9Type(str, Enum):
    RADIO = "RADIO"


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


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


class FieldUpdateDocumentFieldFieldValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9FieldMetaType
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[List[FieldUpdateDocumentFieldFieldValuesTypedDict]]


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9FieldMeta(
    BaseModel
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9FieldMetaType

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


class FieldUpdateDocumentFieldField9TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9FieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField9(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9Type

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

    field_meta: Annotated[
        Optional[
            FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody9FieldMeta
        ],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8Type(str, Enum):
    NUMBER = "NUMBER"


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


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8FieldMetaType
    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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8FieldMeta(
    BaseModel
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8FieldMetaType

    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 FieldUpdateDocumentFieldField8TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8FieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField8(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8Type

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

    field_meta: Annotated[
        Optional[
            FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody8FieldMeta
        ],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7Type(str, Enum):
    TEXT = "TEXT"


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


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7FieldMetaTypedDict(
    TypedDict
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7FieldMetaType
    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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7FieldMeta(
    BaseModel
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7FieldMetaType

    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 FieldUpdateDocumentFieldField7TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7FieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField7(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7Type

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

    field_meta: Annotated[
        Optional[
            FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody7FieldMeta
        ],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody6Type(str, Enum):
    DATE = "DATE"


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


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


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBodyFieldMeta(
    BaseModel
):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody6FieldMetaType

    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 FieldUpdateDocumentFieldField6TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody6Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBodyFieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField6(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody6Type

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

    field_meta: Annotated[
        Optional[
            FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBodyFieldMeta
        ],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody5Type(str, Enum):
    EMAIL = "EMAIL"


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


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


class FieldUpdateDocumentFieldFieldDocumentsFieldsRequestFieldMeta(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody5FieldMetaType

    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 FieldUpdateDocumentFieldField5TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody5Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsRequestFieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField5(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody5Type

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

    field_meta: Annotated[
        Optional[FieldUpdateDocumentFieldFieldDocumentsFieldsRequestFieldMeta],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody4Type(str, Enum):
    NAME = "NAME"


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


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


class FieldUpdateDocumentFieldFieldDocumentsFieldsFieldMeta(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody4FieldMetaType

    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 FieldUpdateDocumentFieldField4TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody4Type
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[
        FieldUpdateDocumentFieldFieldDocumentsFieldsFieldMetaTypedDict
    ]
    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 FieldUpdateDocumentFieldField4(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBody4Type

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

    field_meta: Annotated[
        Optional[FieldUpdateDocumentFieldFieldDocumentsFieldsFieldMeta],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsRequestType(str, Enum):
    INITIALS = "INITIALS"


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


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


class FieldUpdateDocumentFieldFieldFieldMeta(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestRequestBodyType

    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 FieldUpdateDocumentFieldField3TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestType
    id: float
    r"""The ID of the field to update."""
    field_meta: NotRequired[FieldUpdateDocumentFieldFieldFieldMetaTypedDict]
    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 FieldUpdateDocumentFieldField3(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsRequestType

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

    field_meta: Annotated[
        Optional[FieldUpdateDocumentFieldFieldFieldMeta],
        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 FieldUpdateDocumentFieldFieldDocumentsFieldsType(str, Enum):
    FREE_SIGNATURE = "FREE_SIGNATURE"


class FieldUpdateDocumentFieldField2TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsType
    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 FieldUpdateDocumentFieldField2(BaseModel):
    type: FieldUpdateDocumentFieldFieldDocumentsFieldsType

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


class FieldUpdateDocumentFieldField1TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldType
    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 FieldUpdateDocumentFieldField1(BaseModel):
    type: FieldUpdateDocumentFieldFieldType

    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."""


FieldUpdateDocumentFieldFieldTypedDict = TypeAliasType(
    "FieldUpdateDocumentFieldFieldTypedDict",
    Union[
        FieldUpdateDocumentFieldField1TypedDict,
        FieldUpdateDocumentFieldField2TypedDict,
        FieldUpdateDocumentFieldField3TypedDict,
        FieldUpdateDocumentFieldField4TypedDict,
        FieldUpdateDocumentFieldField5TypedDict,
        FieldUpdateDocumentFieldField6TypedDict,
        FieldUpdateDocumentFieldField7TypedDict,
        FieldUpdateDocumentFieldField8TypedDict,
        FieldUpdateDocumentFieldField9TypedDict,
        FieldUpdateDocumentFieldField10TypedDict,
        FieldUpdateDocumentFieldField11TypedDict,
    ],
)


FieldUpdateDocumentFieldField = TypeAliasType(
    "FieldUpdateDocumentFieldField",
    Union[
        FieldUpdateDocumentFieldField1,
        FieldUpdateDocumentFieldField2,
        FieldUpdateDocumentFieldField3,
        FieldUpdateDocumentFieldField4,
        FieldUpdateDocumentFieldField5,
        FieldUpdateDocumentFieldField6,
        FieldUpdateDocumentFieldField7,
        FieldUpdateDocumentFieldField8,
        FieldUpdateDocumentFieldField9,
        FieldUpdateDocumentFieldField10,
        FieldUpdateDocumentFieldField11,
    ],
)


class FieldUpdateDocumentFieldRequestBodyTypedDict(TypedDict):
    document_id: float
    field: FieldUpdateDocumentFieldFieldTypedDict


class FieldUpdateDocumentFieldRequestBody(BaseModel):
    document_id: Annotated[float, pydantic.Field(alias="documentId")]

    field: FieldUpdateDocumentFieldField


class FieldUpdateDocumentFieldDocumentsFieldsIssuesTypedDict(TypedDict):
    message: str


class FieldUpdateDocumentFieldDocumentsFieldsIssues(BaseModel):
    message: str


class FieldUpdateDocumentFieldDocumentsFieldsResponseResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateDocumentFieldDocumentsFieldsIssues]] = None


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

    data: FieldUpdateDocumentFieldDocumentsFieldsResponseResponseBodyData

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

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


class FieldUpdateDocumentFieldIssuesTypedDict(TypedDict):
    message: str


class FieldUpdateDocumentFieldIssues(BaseModel):
    message: str


class FieldUpdateDocumentFieldDocumentsFieldsResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FieldUpdateDocumentFieldIssues]] = None


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

    data: FieldUpdateDocumentFieldDocumentsFieldsResponseBodyData

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

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


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


class FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponseValuesTypedDict(
    TypedDict
):
    value: str


class FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponseValues(BaseModel):
    value: str


class FieldUpdateDocumentFieldFieldMeta9TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBody9Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponseValuesTypedDict]
    ]
    default_value: NotRequired[str]


class FieldUpdateDocumentFieldFieldMeta9(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBody9Type

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

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


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


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


class FieldUpdateDocumentFieldFieldMetaDocumentsFieldsValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateDocumentFieldFieldMeta8TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBody8Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[
        List[FieldUpdateDocumentFieldFieldMetaDocumentsFieldsValuesTypedDict]
    ]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]


class FieldUpdateDocumentFieldFieldMeta8(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBody8Type

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

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

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


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


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


class FieldUpdateDocumentFieldFieldMetaValues(BaseModel):
    id: float

    checked: bool

    value: str


class FieldUpdateDocumentFieldFieldMeta7TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBody7Type
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    values: NotRequired[List[FieldUpdateDocumentFieldFieldMetaValuesTypedDict]]


class FieldUpdateDocumentFieldFieldMeta7(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBody7Type

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


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


class FieldUpdateDocumentFieldFieldMeta6TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBodyType
    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 FieldUpdateDocumentFieldFieldMeta6(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONResponseBodyType

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


class FieldUpdateDocumentFieldFieldMeta5TypedDict(TypedDict):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONType
    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 FieldUpdateDocumentFieldFieldMeta5(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200ApplicationJSONType

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


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


class FieldUpdateDocumentFieldFieldMeta4(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponse200Type

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


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


class FieldUpdateDocumentFieldFieldMeta3(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsResponseType

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


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


class FieldUpdateDocumentFieldFieldMeta2(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaDocumentsFieldsType

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


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


class FieldUpdateDocumentFieldFieldMeta1(BaseModel):
    type: FieldUpdateDocumentFieldFieldMetaType

    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


FieldUpdateDocumentFieldFieldMetaTypedDict = TypeAliasType(
    "FieldUpdateDocumentFieldFieldMetaTypedDict",
    Union[
        FieldUpdateDocumentFieldFieldMeta1TypedDict,
        FieldUpdateDocumentFieldFieldMeta2TypedDict,
        FieldUpdateDocumentFieldFieldMeta3TypedDict,
        FieldUpdateDocumentFieldFieldMeta4TypedDict,
        FieldUpdateDocumentFieldFieldMeta7TypedDict,
        FieldUpdateDocumentFieldFieldMeta9TypedDict,
        FieldUpdateDocumentFieldFieldMeta5TypedDict,
        FieldUpdateDocumentFieldFieldMeta8TypedDict,
        FieldUpdateDocumentFieldFieldMeta6TypedDict,
    ],
)


FieldUpdateDocumentFieldFieldMeta = TypeAliasType(
    "FieldUpdateDocumentFieldFieldMeta",
    Union[
        FieldUpdateDocumentFieldFieldMeta1,
        FieldUpdateDocumentFieldFieldMeta2,
        FieldUpdateDocumentFieldFieldMeta3,
        FieldUpdateDocumentFieldFieldMeta4,
        FieldUpdateDocumentFieldFieldMeta7,
        FieldUpdateDocumentFieldFieldMeta9,
        FieldUpdateDocumentFieldFieldMeta5,
        FieldUpdateDocumentFieldFieldMeta8,
        FieldUpdateDocumentFieldFieldMeta6,
    ],
)


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

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


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

    type: FieldUpdateDocumentFieldType

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