"""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 get_discriminator
from enum import Enum
import httpx
import pydantic
from pydantic import Discriminator, Tag, model_serializer
from typing import Any, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class RecipientUpdateTemplateRecipientRoleRequest(str, Enum):
    CC = "CC"
    SIGNER = "SIGNER"
    VIEWER = "VIEWER"
    APPROVER = "APPROVER"
    ASSISTANT = "ASSISTANT"


class RecipientUpdateTemplateRecipientAccessAuthRequest(str, Enum):
    ACCOUNT = "ACCOUNT"
    TWO_FACTOR_AUTH = "TWO_FACTOR_AUTH"


class RecipientUpdateTemplateRecipientActionAuthRequest(str, Enum):
    ACCOUNT = "ACCOUNT"
    PASSKEY = "PASSKEY"
    TWO_FACTOR_AUTH = "TWO_FACTOR_AUTH"
    PASSWORD = "PASSWORD"
    EXPLICIT_NONE = "EXPLICIT_NONE"


class RecipientUpdateTemplateRecipientRecipientTypedDict(TypedDict):
    id: float
    email: NotRequired[str]
    name: NotRequired[str]
    role: NotRequired[RecipientUpdateTemplateRecipientRoleRequest]
    signing_order: NotRequired[float]
    access_auth: NotRequired[List[RecipientUpdateTemplateRecipientAccessAuthRequest]]
    action_auth: NotRequired[List[RecipientUpdateTemplateRecipientActionAuthRequest]]


class RecipientUpdateTemplateRecipientRecipient(BaseModel):
    id: float

    email: Optional[str] = None

    name: Optional[str] = None

    role: Optional[RecipientUpdateTemplateRecipientRoleRequest] = None

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

    access_auth: Annotated[
        Optional[List[RecipientUpdateTemplateRecipientAccessAuthRequest]],
        pydantic.Field(alias="accessAuth"),
    ] = None

    action_auth: Annotated[
        Optional[List[RecipientUpdateTemplateRecipientActionAuthRequest]],
        pydantic.Field(alias="actionAuth"),
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["email", "name", "role", "signingOrder", "accessAuth", "actionAuth"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


class RecipientUpdateTemplateRecipientRequestTypedDict(TypedDict):
    template_id: float
    recipient: RecipientUpdateTemplateRecipientRecipientTypedDict


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

    recipient: RecipientUpdateTemplateRecipientRecipient


class RecipientUpdateTemplateRecipientInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class RecipientUpdateTemplateRecipientInternalServerErrorIssue(BaseModel):
    message: str


class RecipientUpdateTemplateRecipientInternalServerErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[RecipientUpdateTemplateRecipientInternalServerErrorIssue]] = (
        None
    )


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

    data: RecipientUpdateTemplateRecipientInternalServerErrorData = field(hash=False)

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


class RecipientUpdateTemplateRecipientForbiddenIssue(BaseModel):
    message: str


class RecipientUpdateTemplateRecipientForbiddenErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[RecipientUpdateTemplateRecipientForbiddenIssue]] = None


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

    data: RecipientUpdateTemplateRecipientForbiddenErrorData = field(hash=False)

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


class RecipientUpdateTemplateRecipientUnauthorizedIssue(BaseModel):
    message: str


class RecipientUpdateTemplateRecipientUnauthorizedErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[RecipientUpdateTemplateRecipientUnauthorizedIssue]] = None


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

    data: RecipientUpdateTemplateRecipientUnauthorizedErrorData = field(hash=False)

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


class RecipientUpdateTemplateRecipientBadRequestIssue(BaseModel):
    message: str


class RecipientUpdateTemplateRecipientBadRequestErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[RecipientUpdateTemplateRecipientBadRequestIssue]] = None


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

    data: RecipientUpdateTemplateRecipientBadRequestErrorData = field(hash=False)

    def __init__(
        self,
        data: RecipientUpdateTemplateRecipientBadRequestErrorData,
        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 RecipientUpdateTemplateRecipientRoleResponse(str, Enum):
    CC = "CC"
    SIGNER = "SIGNER"
    VIEWER = "VIEWER"
    APPROVER = "APPROVER"
    ASSISTANT = "ASSISTANT"


class RecipientUpdateTemplateRecipientReadStatus(str, Enum):
    NOT_OPENED = "NOT_OPENED"
    OPENED = "OPENED"


class RecipientUpdateTemplateRecipientSigningStatus(str, Enum):
    NOT_SIGNED = "NOT_SIGNED"
    SIGNED = "SIGNED"
    REJECTED = "REJECTED"


class RecipientUpdateTemplateRecipientSendStatus(str, Enum):
    NOT_SENT = "NOT_SENT"
    SENT = "SENT"


class RecipientUpdateTemplateRecipientAuthOptionsAccessAuth(str, Enum):
    ACCOUNT = "ACCOUNT"
    TWO_FACTOR_AUTH = "TWO_FACTOR_AUTH"


class RecipientUpdateTemplateRecipientAuthOptionsActionAuth(str, Enum):
    ACCOUNT = "ACCOUNT"
    PASSKEY = "PASSKEY"
    TWO_FACTOR_AUTH = "TWO_FACTOR_AUTH"
    PASSWORD = "PASSWORD"
    EXPLICIT_NONE = "EXPLICIT_NONE"


class RecipientUpdateTemplateRecipientAuthOptionsTypedDict(TypedDict):
    access_auth: List[RecipientUpdateTemplateRecipientAuthOptionsAccessAuth]
    action_auth: List[RecipientUpdateTemplateRecipientAuthOptionsActionAuth]


class RecipientUpdateTemplateRecipientAuthOptions(BaseModel):
    access_auth: Annotated[
        List[RecipientUpdateTemplateRecipientAuthOptionsAccessAuth],
        pydantic.Field(alias="accessAuth"),
    ]

    action_auth: Annotated[
        List[RecipientUpdateTemplateRecipientAuthOptionsActionAuth],
        pydantic.Field(alias="actionAuth"),
    ]


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


class RecipientUpdateTemplateRecipientValue3TypedDict(TypedDict):
    value: str


class RecipientUpdateTemplateRecipientValue3(BaseModel):
    value: str


class RecipientUpdateTemplateRecipientFieldMetaDropdownTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeDropdown
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[RecipientUpdateTemplateRecipientValue3TypedDict]]
    default_value: NotRequired[str]


class RecipientUpdateTemplateRecipientFieldMetaDropdown(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeDropdown

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "label",
                "placeholder",
                "required",
                "readOnly",
                "fontSize",
                "values",
                "defaultValue",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


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


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


class RecipientUpdateTemplateRecipientValue2(BaseModel):
    id: float

    checked: bool

    value: str


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


class RecipientUpdateTemplateRecipientFieldMetaCheckboxTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeCheckbox
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[RecipientUpdateTemplateRecipientValue2TypedDict]]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]
    direction: NotRequired[RecipientUpdateTemplateRecipientDirection2]


class RecipientUpdateTemplateRecipientFieldMetaCheckbox(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeCheckbox

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

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

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "label",
                "placeholder",
                "required",
                "readOnly",
                "fontSize",
                "values",
                "validationRule",
                "validationLength",
                "direction",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


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


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


class RecipientUpdateTemplateRecipientValue1(BaseModel):
    id: float

    checked: bool

    value: str


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


class RecipientUpdateTemplateRecipientFieldMetaRadioTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeRadio
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[RecipientUpdateTemplateRecipientValue1TypedDict]]
    direction: NotRequired[RecipientUpdateTemplateRecipientDirection1]


class RecipientUpdateTemplateRecipientFieldMetaRadio(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeRadio

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "label",
                "placeholder",
                "required",
                "readOnly",
                "fontSize",
                "values",
                "direction",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


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


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


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


class RecipientUpdateTemplateRecipientFieldMetaNumberTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeNumber
    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[RecipientUpdateTemplateRecipientTextAlign6]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[
        Nullable[RecipientUpdateTemplateRecipientVerticalAlign2]
    ]


class RecipientUpdateTemplateRecipientFieldMetaNumber(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeNumber

    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[RecipientUpdateTemplateRecipientTextAlign6],
        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[RecipientUpdateTemplateRecipientVerticalAlign2],
        pydantic.Field(alias="verticalAlign"),
    ] = UNSET

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

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


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


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


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


class RecipientUpdateTemplateRecipientFieldMetaTextTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeText
    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[RecipientUpdateTemplateRecipientTextAlign5]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[
        Nullable[RecipientUpdateTemplateRecipientVerticalAlign1]
    ]


class RecipientUpdateTemplateRecipientFieldMetaText(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeText

    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[RecipientUpdateTemplateRecipientTextAlign5],
        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[RecipientUpdateTemplateRecipientVerticalAlign1],
        pydantic.Field(alias="verticalAlign"),
    ] = UNSET

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

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


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


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


class RecipientUpdateTemplateRecipientFieldMetaDateTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeDate
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[RecipientUpdateTemplateRecipientTextAlign4]


class RecipientUpdateTemplateRecipientFieldMetaDate(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeDate

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["label", "placeholder", "required", "readOnly", "fontSize", "textAlign"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


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


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


class RecipientUpdateTemplateRecipientFieldMetaEmailTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeEmail
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[RecipientUpdateTemplateRecipientTextAlign3]


class RecipientUpdateTemplateRecipientFieldMetaEmail(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeEmail

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["label", "placeholder", "required", "readOnly", "fontSize", "textAlign"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


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


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


class RecipientUpdateTemplateRecipientFieldMetaNameTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeName
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[RecipientUpdateTemplateRecipientTextAlign2]


class RecipientUpdateTemplateRecipientFieldMetaName(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeName

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["label", "placeholder", "required", "readOnly", "fontSize", "textAlign"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


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


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


class RecipientUpdateTemplateRecipientFieldMetaInitialsTypedDict(TypedDict):
    type: RecipientUpdateTemplateRecipientTypeInitials
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[RecipientUpdateTemplateRecipientTextAlign1]


class RecipientUpdateTemplateRecipientFieldMetaInitials(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeInitials

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["label", "placeholder", "required", "readOnly", "fontSize", "textAlign"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


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


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


class RecipientUpdateTemplateRecipientFieldMetaSignature(BaseModel):
    type: RecipientUpdateTemplateRecipientTypeSignature

    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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["label", "placeholder", "required", "readOnly", "fontSize"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


RecipientUpdateTemplateRecipientFieldMetaUnionTypedDict = TypeAliasType(
    "RecipientUpdateTemplateRecipientFieldMetaUnionTypedDict",
    Union[
        RecipientUpdateTemplateRecipientFieldMetaSignatureTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaInitialsTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaNameTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaEmailTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaDateTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaRadioTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaDropdownTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaCheckboxTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaTextTypedDict,
        RecipientUpdateTemplateRecipientFieldMetaNumberTypedDict,
    ],
)


RecipientUpdateTemplateRecipientFieldMetaUnion = Annotated[
    Union[
        Annotated[RecipientUpdateTemplateRecipientFieldMetaSignature, Tag("signature")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaInitials, Tag("initials")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaName, Tag("name")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaEmail, Tag("email")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaDate, Tag("date")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaText, Tag("text")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaNumber, Tag("number")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaRadio, Tag("radio")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaCheckbox, Tag("checkbox")],
        Annotated[RecipientUpdateTemplateRecipientFieldMetaDropdown, Tag("dropdown")],
    ],
    Discriminator(lambda m: get_discriminator(m, "type", "type")),
]


class RecipientUpdateTemplateRecipientFieldTypedDict(TypedDict):
    envelope_id: str
    envelope_item_id: str
    type: RecipientUpdateTemplateRecipientType
    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[RecipientUpdateTemplateRecipientFieldMetaUnionTypedDict]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

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

    type: RecipientUpdateTemplateRecipientType

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

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["documentId", "templateId"])
        nullable_fields = set(["fieldMeta", "documentId", "templateId"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


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

    envelope_id: str
    role: RecipientUpdateTemplateRecipientRoleResponse
    read_status: RecipientUpdateTemplateRecipientReadStatus
    signing_status: RecipientUpdateTemplateRecipientSigningStatus
    send_status: RecipientUpdateTemplateRecipientSendStatus
    id: float
    email: str
    name: str
    token: str
    document_deleted_at: Nullable[str]
    expired: Nullable[str]
    signed_at: Nullable[str]
    auth_options: Nullable[RecipientUpdateTemplateRecipientAuthOptionsTypedDict]
    signing_order: Nullable[float]
    rejection_reason: Nullable[str]
    fields: List[RecipientUpdateTemplateRecipientFieldTypedDict]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

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

    role: RecipientUpdateTemplateRecipientRoleResponse

    read_status: Annotated[
        RecipientUpdateTemplateRecipientReadStatus, pydantic.Field(alias="readStatus")
    ]

    signing_status: Annotated[
        RecipientUpdateTemplateRecipientSigningStatus,
        pydantic.Field(alias="signingStatus"),
    ]

    send_status: Annotated[
        RecipientUpdateTemplateRecipientSendStatus, pydantic.Field(alias="sendStatus")
    ]

    id: float

    email: str

    name: str

    token: str

    document_deleted_at: Annotated[
        Nullable[str], pydantic.Field(alias="documentDeletedAt")
    ]

    expired: Nullable[str]

    signed_at: Annotated[Nullable[str], pydantic.Field(alias="signedAt")]

    auth_options: Annotated[
        Nullable[RecipientUpdateTemplateRecipientAuthOptions],
        pydantic.Field(alias="authOptions"),
    ]

    signing_order: Annotated[Nullable[float], pydantic.Field(alias="signingOrder")]

    rejection_reason: Annotated[Nullable[str], pydantic.Field(alias="rejectionReason")]

    fields: List[RecipientUpdateTemplateRecipientField]

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["documentId", "templateId"])
        nullable_fields = set(
            [
                "documentDeletedAt",
                "expired",
                "signedAt",
                "authOptions",
                "signingOrder",
                "rejectionReason",
                "documentId",
                "templateId",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m
