"""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, QueryParamMetadata
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 TemplateFindTemplatesQueryParamType(str, Enum):
    r"""Filter templates by type."""

    PUBLIC = "PUBLIC"
    PRIVATE = "PRIVATE"


class TemplateFindTemplatesRequestTypedDict(TypedDict):
    query: NotRequired[str]
    r"""The search query."""
    page: NotRequired[float]
    r"""The pagination page number, starts at 1."""
    per_page: NotRequired[float]
    r"""The number of items per page."""
    type: NotRequired[TemplateFindTemplatesQueryParamType]
    r"""Filter templates by type."""
    folder_id: NotRequired[str]
    r"""The ID of the folder to filter templates by."""


class TemplateFindTemplatesRequest(BaseModel):
    query: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The search query."""

    page: Annotated[
        Optional[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The pagination page number, starts at 1."""

    per_page: Annotated[
        Optional[float],
        pydantic.Field(alias="perPage"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The number of items per page."""

    type: Annotated[
        Optional[TemplateFindTemplatesQueryParamType],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""Filter templates by type."""

    folder_id: Annotated[
        Optional[str],
        pydantic.Field(alias="folderId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The ID of the folder to filter templates by."""


class TemplateFindTemplatesInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class TemplateFindTemplatesInternalServerErrorIssue(BaseModel):
    message: str


class TemplateFindTemplatesInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateFindTemplatesInternalServerErrorIssue]] = None


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

    data: TemplateFindTemplatesInternalServerErrorData = field(hash=False)

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


class TemplateFindTemplatesNotFoundIssue(BaseModel):
    message: str


class TemplateFindTemplatesNotFoundErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateFindTemplatesNotFoundIssue]] = None


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

    data: TemplateFindTemplatesNotFoundErrorData = field(hash=False)

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


class TemplateFindTemplatesForbiddenIssue(BaseModel):
    message: str


class TemplateFindTemplatesForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateFindTemplatesForbiddenIssue]] = None


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

    data: TemplateFindTemplatesForbiddenErrorData = field(hash=False)

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


class TemplateFindTemplatesUnauthorizedIssue(BaseModel):
    message: str


class TemplateFindTemplatesUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateFindTemplatesUnauthorizedIssue]] = None


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

    data: TemplateFindTemplatesUnauthorizedErrorData = field(hash=False)

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


class TemplateFindTemplatesBadRequestIssue(BaseModel):
    message: str


class TemplateFindTemplatesBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateFindTemplatesBadRequestIssue]] = None


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

    data: TemplateFindTemplatesBadRequestErrorData = field(hash=False)

    def __init__(
        self,
        data: TemplateFindTemplatesBadRequestErrorData,
        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 TemplateFindTemplatesDataType(str, Enum):
    PUBLIC = "PUBLIC"
    PRIVATE = "PRIVATE"


class TemplateFindTemplatesVisibility(str, Enum):
    EVERYONE = "EVERYONE"
    MANAGER_AND_ABOVE = "MANAGER_AND_ABOVE"
    ADMIN = "ADMIN"


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


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


class TemplateFindTemplatesAuthOptionsTypedDict(TypedDict):
    global_access_auth: List[TemplateFindTemplatesGlobalAccessAuth]
    global_action_auth: List[TemplateFindTemplatesGlobalActionAuth]


class TemplateFindTemplatesAuthOptions(BaseModel):
    global_access_auth: Annotated[
        List[TemplateFindTemplatesGlobalAccessAuth],
        pydantic.Field(alias="globalAccessAuth"),
    ]

    global_action_auth: Annotated[
        List[TemplateFindTemplatesGlobalActionAuth],
        pydantic.Field(alias="globalActionAuth"),
    ]


class TemplateFindTemplatesTeamTypedDict(TypedDict):
    id: float
    url: str


class TemplateFindTemplatesTeam(BaseModel):
    id: float

    url: str


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


class TemplateFindTemplatesValue3TypedDict(TypedDict):
    value: str


class TemplateFindTemplatesValue3(BaseModel):
    value: str


class TemplateFindTemplatesFieldMetaDropdownTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeDropdown
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[TemplateFindTemplatesValue3TypedDict]]
    default_value: NotRequired[str]


class TemplateFindTemplatesFieldMetaDropdown(BaseModel):
    type: TemplateFindTemplatesTypeDropdown

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

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


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


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


class TemplateFindTemplatesValue2(BaseModel):
    id: float

    checked: bool

    value: str


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


class TemplateFindTemplatesFieldMetaCheckboxTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeCheckbox
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[TemplateFindTemplatesValue2TypedDict]]
    validation_rule: NotRequired[str]
    validation_length: NotRequired[float]
    direction: NotRequired[TemplateFindTemplatesDirection2]


class TemplateFindTemplatesFieldMetaCheckbox(BaseModel):
    type: TemplateFindTemplatesTypeCheckbox

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

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

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

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


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


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


class TemplateFindTemplatesValue1(BaseModel):
    id: float

    checked: bool

    value: str


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


class TemplateFindTemplatesFieldMetaRadioTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeRadio
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    values: NotRequired[List[TemplateFindTemplatesValue1TypedDict]]
    direction: NotRequired[TemplateFindTemplatesDirection1]


class TemplateFindTemplatesFieldMetaRadio(BaseModel):
    type: TemplateFindTemplatesTypeRadio

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

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


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


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


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


class TemplateFindTemplatesFieldMetaNumberTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeNumber
    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[TemplateFindTemplatesTextAlign6]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[Nullable[TemplateFindTemplatesVerticalAlign2]]


class TemplateFindTemplatesFieldMetaNumber(BaseModel):
    type: TemplateFindTemplatesTypeNumber

    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[TemplateFindTemplatesTextAlign6], 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[TemplateFindTemplatesVerticalAlign2],
        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 TemplateFindTemplatesTypeText(str, Enum):
    TEXT = "text"


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


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


class TemplateFindTemplatesFieldMetaTextTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeText
    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[TemplateFindTemplatesTextAlign5]
    line_height: NotRequired[Nullable[float]]
    letter_spacing: NotRequired[Nullable[float]]
    vertical_align: NotRequired[Nullable[TemplateFindTemplatesVerticalAlign1]]


class TemplateFindTemplatesFieldMetaText(BaseModel):
    type: TemplateFindTemplatesTypeText

    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[TemplateFindTemplatesTextAlign5], 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[TemplateFindTemplatesVerticalAlign1],
        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 TemplateFindTemplatesTypeDate(str, Enum):
    DATE = "date"


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


class TemplateFindTemplatesFieldMetaDateTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeDate
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[TemplateFindTemplatesTextAlign4]


class TemplateFindTemplatesFieldMetaDate(BaseModel):
    type: TemplateFindTemplatesTypeDate

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


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


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


class TemplateFindTemplatesFieldMetaEmailTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeEmail
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[TemplateFindTemplatesTextAlign3]


class TemplateFindTemplatesFieldMetaEmail(BaseModel):
    type: TemplateFindTemplatesTypeEmail

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


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


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


class TemplateFindTemplatesFieldMetaNameTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeName
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[TemplateFindTemplatesTextAlign2]


class TemplateFindTemplatesFieldMetaName(BaseModel):
    type: TemplateFindTemplatesTypeName

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


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


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


class TemplateFindTemplatesFieldMetaInitialsTypedDict(TypedDict):
    type: TemplateFindTemplatesTypeInitials
    label: NotRequired[str]
    placeholder: NotRequired[str]
    required: NotRequired[bool]
    read_only: NotRequired[bool]
    font_size: NotRequired[float]
    text_align: NotRequired[TemplateFindTemplatesTextAlign1]


class TemplateFindTemplatesFieldMetaInitials(BaseModel):
    type: TemplateFindTemplatesTypeInitials

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


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


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


class TemplateFindTemplatesFieldMetaSignature(BaseModel):
    type: TemplateFindTemplatesTypeSignature

    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


TemplateFindTemplatesFieldMetaUnionTypedDict = TypeAliasType(
    "TemplateFindTemplatesFieldMetaUnionTypedDict",
    Union[
        TemplateFindTemplatesFieldMetaSignatureTypedDict,
        TemplateFindTemplatesFieldMetaInitialsTypedDict,
        TemplateFindTemplatesFieldMetaNameTypedDict,
        TemplateFindTemplatesFieldMetaEmailTypedDict,
        TemplateFindTemplatesFieldMetaDateTypedDict,
        TemplateFindTemplatesFieldMetaRadioTypedDict,
        TemplateFindTemplatesFieldMetaDropdownTypedDict,
        TemplateFindTemplatesFieldMetaCheckboxTypedDict,
        TemplateFindTemplatesFieldMetaTextTypedDict,
        TemplateFindTemplatesFieldMetaNumberTypedDict,
    ],
)


TemplateFindTemplatesFieldMetaUnion = TypeAliasType(
    "TemplateFindTemplatesFieldMetaUnion",
    Union[
        TemplateFindTemplatesFieldMetaSignature,
        TemplateFindTemplatesFieldMetaInitials,
        TemplateFindTemplatesFieldMetaName,
        TemplateFindTemplatesFieldMetaEmail,
        TemplateFindTemplatesFieldMetaDate,
        TemplateFindTemplatesFieldMetaRadio,
        TemplateFindTemplatesFieldMetaDropdown,
        TemplateFindTemplatesFieldMetaCheckbox,
        TemplateFindTemplatesFieldMetaText,
        TemplateFindTemplatesFieldMetaNumber,
    ],
)


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


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

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

    type: TemplateFindTemplatesFieldType

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

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

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

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

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


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


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


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


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


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


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


class TemplateFindTemplatesRecipientAuthOptionsTypedDict(TypedDict):
    access_auth: List[TemplateFindTemplatesAccessAuth]
    action_auth: List[TemplateFindTemplatesActionAuth]


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

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


class TemplateFindTemplatesRecipientTypedDict(TypedDict):
    envelope_id: str
    role: TemplateFindTemplatesRole
    read_status: TemplateFindTemplatesReadStatus
    signing_status: TemplateFindTemplatesSigningStatus
    send_status: TemplateFindTemplatesSendStatus
    id: float
    email: str
    name: str
    token: str
    document_deleted_at: Nullable[str]
    expired: Nullable[str]
    signed_at: Nullable[str]
    auth_options: Nullable[TemplateFindTemplatesRecipientAuthOptionsTypedDict]
    signing_order: Nullable[float]
    rejection_reason: Nullable[str]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

    role: TemplateFindTemplatesRole

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

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

    send_status: Annotated[
        TemplateFindTemplatesSendStatus, 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[TemplateFindTemplatesRecipientAuthOptions],
        pydantic.Field(alias="authOptions"),
    ]

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

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

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

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

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

        serialized = handler(self)

        m = {}

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

            optional_nullable = k in optional_fields and k in nullable_fields
            is_set = (
                self.__pydantic_fields_set__.intersection({n})
                or k in null_default_fields
            )  # pylint: disable=no-member

            if val is not None and val != UNSET_SENTINEL:
                m[k] = val
            elif val != UNSET_SENTINEL and (
                not k in optional_fields or (optional_nullable and is_set)
            ):
                m[k] = val

        return m


class TemplateFindTemplatesSigningOrder(str, Enum):
    PARALLEL = "PARALLEL"
    SEQUENTIAL = "SEQUENTIAL"


class TemplateFindTemplatesDistributionMethod(str, Enum):
    EMAIL = "EMAIL"
    NONE = "NONE"


class TemplateFindTemplatesTemplateMetaTypedDict(TypedDict):
    signing_order: TemplateFindTemplatesSigningOrder
    distribution_method: TemplateFindTemplatesDistributionMethod


class TemplateFindTemplatesTemplateMeta(BaseModel):
    signing_order: Annotated[
        TemplateFindTemplatesSigningOrder, pydantic.Field(alias="signingOrder")
    ]

    distribution_method: Annotated[
        TemplateFindTemplatesDistributionMethod,
        pydantic.Field(alias="distributionMethod"),
    ]


class TemplateFindTemplatesDirectLinkTypedDict(TypedDict):
    token: str
    enabled: bool


class TemplateFindTemplatesDirectLink(BaseModel):
    token: str

    enabled: bool


class TemplateFindTemplatesDataTypedDict(TypedDict):
    type: TemplateFindTemplatesDataType
    visibility: TemplateFindTemplatesVisibility
    id: float
    external_id: Nullable[str]
    title: str
    user_id: float
    team_id: float
    auth_options: Nullable[TemplateFindTemplatesAuthOptionsTypedDict]
    created_at: str
    updated_at: str
    public_title: str
    public_description: str
    folder_id: Nullable[str]
    use_legacy_field_insertion: bool
    envelope_id: str
    team: Nullable[TemplateFindTemplatesTeamTypedDict]
    fields: List[TemplateFindTemplatesFieldTypedDict]
    recipients: List[TemplateFindTemplatesRecipientTypedDict]
    template_meta: Nullable[TemplateFindTemplatesTemplateMetaTypedDict]
    direct_link: Nullable[TemplateFindTemplatesDirectLinkTypedDict]
    template_document_data_id: NotRequired[str]


class TemplateFindTemplatesData(BaseModel):
    type: TemplateFindTemplatesDataType

    visibility: TemplateFindTemplatesVisibility

    id: float

    external_id: Annotated[Nullable[str], pydantic.Field(alias="externalId")]

    title: str

    user_id: Annotated[float, pydantic.Field(alias="userId")]

    team_id: Annotated[float, pydantic.Field(alias="teamId")]

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

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]

    updated_at: Annotated[str, pydantic.Field(alias="updatedAt")]

    public_title: Annotated[str, pydantic.Field(alias="publicTitle")]

    public_description: Annotated[str, pydantic.Field(alias="publicDescription")]

    folder_id: Annotated[Nullable[str], pydantic.Field(alias="folderId")]

    use_legacy_field_insertion: Annotated[
        bool, pydantic.Field(alias="useLegacyFieldInsertion")
    ]

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

    team: Nullable[TemplateFindTemplatesTeam]

    fields: List[TemplateFindTemplatesField]

    recipients: List[TemplateFindTemplatesRecipient]

    template_meta: Annotated[
        Nullable[TemplateFindTemplatesTemplateMeta],
        pydantic.Field(alias="templateMeta"),
    ]

    direct_link: Annotated[
        Nullable[TemplateFindTemplatesDirectLink], pydantic.Field(alias="directLink")
    ]

    template_document_data_id: Annotated[
        Optional[str], pydantic.Field(alias="templateDocumentDataId")
    ] = ""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["templateDocumentDataId"]
        nullable_fields = [
            "externalId",
            "authOptions",
            "folderId",
            "team",
            "templateMeta",
            "directLink",
        ]
        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 TemplateFindTemplatesResponseTypedDict(TypedDict):
    r"""Successful response"""

    data: List[TemplateFindTemplatesDataTypedDict]
    count: float
    current_page: float
    per_page: float
    total_pages: float


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

    data: List[TemplateFindTemplatesData]

    count: float

    current_page: Annotated[float, pydantic.Field(alias="currentPage")]

    per_page: Annotated[float, pydantic.Field(alias="perPage")]

    total_pages: Annotated[float, pydantic.Field(alias="totalPages")]
