"""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 documenso_sdk.utils import FieldMetadata, PathParamMetadata
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 EnvelopeFieldGetRequestTypedDict(TypedDict):
    field_id: float


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


class EnvelopeFieldGetInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class EnvelopeFieldGetInternalServerErrorIssue(BaseModel):
    message: str


class EnvelopeFieldGetInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeFieldGetInternalServerErrorIssue]] = None


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

    data: EnvelopeFieldGetInternalServerErrorData = field(hash=False)

    def __init__(
        self,
        data: EnvelopeFieldGetInternalServerErrorData,
        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 EnvelopeFieldGetNotFoundIssueTypedDict(TypedDict):
    message: str


class EnvelopeFieldGetNotFoundIssue(BaseModel):
    message: str


class EnvelopeFieldGetNotFoundErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeFieldGetNotFoundIssue]] = None


@dataclass(unsafe_hash=True)
class EnvelopeFieldGetNotFoundError(DocumensoError):
    r"""Not found"""

    data: EnvelopeFieldGetNotFoundErrorData = field(hash=False)

    def __init__(
        self,
        data: EnvelopeFieldGetNotFoundErrorData,
        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 EnvelopeFieldGetForbiddenIssueTypedDict(TypedDict):
    message: str


class EnvelopeFieldGetForbiddenIssue(BaseModel):
    message: str


class EnvelopeFieldGetForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeFieldGetForbiddenIssue]] = None


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

    data: EnvelopeFieldGetForbiddenErrorData = field(hash=False)

    def __init__(
        self,
        data: EnvelopeFieldGetForbiddenErrorData,
        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 EnvelopeFieldGetUnauthorizedIssueTypedDict(TypedDict):
    message: str


class EnvelopeFieldGetUnauthorizedIssue(BaseModel):
    message: str


class EnvelopeFieldGetUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeFieldGetUnauthorizedIssue]] = None


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

    data: EnvelopeFieldGetUnauthorizedErrorData = field(hash=False)

    def __init__(
        self,
        data: EnvelopeFieldGetUnauthorizedErrorData,
        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 EnvelopeFieldGetBadRequestIssueTypedDict(TypedDict):
    message: str


class EnvelopeFieldGetBadRequestIssue(BaseModel):
    message: str


class EnvelopeFieldGetBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeFieldGetBadRequestIssue]] = None


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

    data: EnvelopeFieldGetBadRequestErrorData = field(hash=False)

    def __init__(
        self,
        data: EnvelopeFieldGetBadRequestErrorData,
        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 EnvelopeFieldGetType(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 EnvelopeFieldGetTypeDropdown(str, Enum):
    DROPDOWN = "dropdown"


class EnvelopeFieldGetValue3TypedDict(TypedDict):
    value: str


class EnvelopeFieldGetValue3(BaseModel):
    value: str


class EnvelopeFieldGetFieldMetaDropdownTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeDropdown
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[EnvelopeFieldGetValue3TypedDict]]
    default_value: NotRequired[str]


class EnvelopeFieldGetFieldMetaDropdown(BaseModel):
    type: EnvelopeFieldGetTypeDropdown

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

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


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


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


class EnvelopeFieldGetValue2(BaseModel):
    id: float

    checked: bool

    value: str


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


class EnvelopeFieldGetFieldMetaCheckboxTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeCheckbox
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[EnvelopeFieldGetValue2TypedDict]]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]
    direction: NotRequired[EnvelopeFieldGetDirection2]


class EnvelopeFieldGetFieldMetaCheckbox(BaseModel):
    type: EnvelopeFieldGetTypeCheckbox

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

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

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

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


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


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


class EnvelopeFieldGetValue1(BaseModel):
    id: float

    checked: bool

    value: str


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


class EnvelopeFieldGetFieldMetaRadioTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeRadio
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[EnvelopeFieldGetValue1TypedDict]]
    direction: NotRequired[EnvelopeFieldGetDirection1]


class EnvelopeFieldGetFieldMetaRadio(BaseModel):
    type: EnvelopeFieldGetTypeRadio

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

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


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


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


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


class EnvelopeFieldGetFieldMetaNumberTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeNumber
    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[EnvelopeFieldGetTextAlign6]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[Nullable[EnvelopeFieldGetVerticalAlign2]]


class EnvelopeFieldGetFieldMetaNumber(BaseModel):
    type: EnvelopeFieldGetTypeNumber

    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[EnvelopeFieldGetTextAlign6], 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[EnvelopeFieldGetVerticalAlign2],
        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 EnvelopeFieldGetTypeText(str, Enum):
    TEXT = "text"


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


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


class EnvelopeFieldGetFieldMetaTextTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeText
    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[EnvelopeFieldGetTextAlign5]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[Nullable[EnvelopeFieldGetVerticalAlign1]]


class EnvelopeFieldGetFieldMetaText(BaseModel):
    type: EnvelopeFieldGetTypeText

    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[EnvelopeFieldGetTextAlign5], 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[EnvelopeFieldGetVerticalAlign1],
        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 EnvelopeFieldGetTypeDate(str, Enum):
    DATE = "date"


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


class EnvelopeFieldGetFieldMetaDateTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeDate
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[EnvelopeFieldGetTextAlign4]


class EnvelopeFieldGetFieldMetaDate(BaseModel):
    type: EnvelopeFieldGetTypeDate

    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[EnvelopeFieldGetTextAlign4], pydantic.Field(alias="textAlign")
    ] = None


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


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


class EnvelopeFieldGetFieldMetaEmailTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeEmail
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[EnvelopeFieldGetTextAlign3]


class EnvelopeFieldGetFieldMetaEmail(BaseModel):
    type: EnvelopeFieldGetTypeEmail

    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[EnvelopeFieldGetTextAlign3], pydantic.Field(alias="textAlign")
    ] = None


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


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


class EnvelopeFieldGetFieldMetaNameTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeName
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[EnvelopeFieldGetTextAlign2]


class EnvelopeFieldGetFieldMetaName(BaseModel):
    type: EnvelopeFieldGetTypeName

    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[EnvelopeFieldGetTextAlign2], pydantic.Field(alias="textAlign")
    ] = None


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


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


class EnvelopeFieldGetFieldMetaInitialsTypedDict(TypedDict):
    type: EnvelopeFieldGetTypeInitials
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[EnvelopeFieldGetTextAlign1]


class EnvelopeFieldGetFieldMetaInitials(BaseModel):
    type: EnvelopeFieldGetTypeInitials

    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[EnvelopeFieldGetTextAlign1], pydantic.Field(alias="textAlign")
    ] = None


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


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


class EnvelopeFieldGetFieldMetaSignature(BaseModel):
    type: EnvelopeFieldGetTypeSignature

    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


EnvelopeFieldGetFieldMetaUnionTypedDict = TypeAliasType(
    "EnvelopeFieldGetFieldMetaUnionTypedDict",
    Union[
        EnvelopeFieldGetFieldMetaSignatureTypedDict,
        EnvelopeFieldGetFieldMetaInitialsTypedDict,
        EnvelopeFieldGetFieldMetaNameTypedDict,
        EnvelopeFieldGetFieldMetaEmailTypedDict,
        EnvelopeFieldGetFieldMetaDateTypedDict,
        EnvelopeFieldGetFieldMetaRadioTypedDict,
        EnvelopeFieldGetFieldMetaDropdownTypedDict,
        EnvelopeFieldGetFieldMetaCheckboxTypedDict,
        EnvelopeFieldGetFieldMetaTextTypedDict,
        EnvelopeFieldGetFieldMetaNumberTypedDict,
    ],
)


EnvelopeFieldGetFieldMetaUnion = TypeAliasType(
    "EnvelopeFieldGetFieldMetaUnion",
    Union[
        EnvelopeFieldGetFieldMetaSignature,
        EnvelopeFieldGetFieldMetaInitials,
        EnvelopeFieldGetFieldMetaName,
        EnvelopeFieldGetFieldMetaEmail,
        EnvelopeFieldGetFieldMetaDate,
        EnvelopeFieldGetFieldMetaRadio,
        EnvelopeFieldGetFieldMetaDropdown,
        EnvelopeFieldGetFieldMetaCheckbox,
        EnvelopeFieldGetFieldMetaText,
        EnvelopeFieldGetFieldMetaNumber,
    ],
)


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

    envelope_id: str
    envelope_item_id: str
    type: EnvelopeFieldGetType
    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[EnvelopeFieldGetFieldMetaUnionTypedDict]


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

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

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

    type: EnvelopeFieldGetType

    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[EnvelopeFieldGetFieldMetaUnion], pydantic.Field(alias="fieldMeta")
    ]

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