"""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, UNSET_SENTINEL
from enum import Enum
import httpx
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class TemplateDuplicateTemplateRequestTypedDict(TypedDict):
    template_id: float


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


class TemplateDuplicateTemplateInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class TemplateDuplicateTemplateInternalServerErrorIssue(BaseModel):
    message: str


class TemplateDuplicateTemplateInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateDuplicateTemplateInternalServerErrorIssue]] = None


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

    data: TemplateDuplicateTemplateInternalServerErrorData = field(hash=False)

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


class TemplateDuplicateTemplateForbiddenIssue(BaseModel):
    message: str


class TemplateDuplicateTemplateForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateDuplicateTemplateForbiddenIssue]] = None


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

    data: TemplateDuplicateTemplateForbiddenErrorData = field(hash=False)

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


class TemplateDuplicateTemplateUnauthorizedIssue(BaseModel):
    message: str


class TemplateDuplicateTemplateUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateDuplicateTemplateUnauthorizedIssue]] = None


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

    data: TemplateDuplicateTemplateUnauthorizedErrorData = field(hash=False)

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


class TemplateDuplicateTemplateBadRequestIssue(BaseModel):
    message: str


class TemplateDuplicateTemplateBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[TemplateDuplicateTemplateBadRequestIssue]] = None


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

    data: TemplateDuplicateTemplateBadRequestErrorData = field(hash=False)

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


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


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


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


class TemplateDuplicateTemplateAuthOptionsTypedDict(TypedDict):
    global_access_auth: List[TemplateDuplicateTemplateGlobalAccessAuth]
    global_action_auth: List[TemplateDuplicateTemplateGlobalActionAuth]


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

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


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

    type: TemplateDuplicateTemplateType
    visibility: TemplateDuplicateTemplateVisibility
    id: float
    external_id: Nullable[str]
    title: str
    user_id: float
    team_id: float
    auth_options: Nullable[TemplateDuplicateTemplateAuthOptionsTypedDict]
    created_at: str
    updated_at: str
    public_title: str
    public_description: str
    folder_id: Nullable[str]
    use_legacy_field_insertion: bool
    envelope_id: str
    template_document_data_id: NotRequired[str]


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

    type: TemplateDuplicateTemplateType

    visibility: TemplateDuplicateTemplateVisibility

    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[TemplateDuplicateTemplateAuthOptions],
        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")]

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