"""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 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 RecipientCreateTemplateRecipientsRoleRequest(str, Enum):
    CC = "CC"
    SIGNER = "SIGNER"
    VIEWER = "VIEWER"
    APPROVER = "APPROVER"
    ASSISTANT = "ASSISTANT"


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


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


class RecipientCreateTemplateRecipientsRecipientRequestTypedDict(TypedDict):
    email: str
    name: str
    role: RecipientCreateTemplateRecipientsRoleRequest
    signing_order: NotRequired[float]
    access_auth: NotRequired[List[RecipientCreateTemplateRecipientsAccessAuthRequest]]
    action_auth: NotRequired[List[RecipientCreateTemplateRecipientsActionAuthRequest]]


class RecipientCreateTemplateRecipientsRecipientRequest(BaseModel):
    email: str

    name: str

    role: RecipientCreateTemplateRecipientsRoleRequest

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

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

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


class RecipientCreateTemplateRecipientsRequestTypedDict(TypedDict):
    template_id: float
    recipients: List[RecipientCreateTemplateRecipientsRecipientRequestTypedDict]


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

    recipients: List[RecipientCreateTemplateRecipientsRecipientRequest]


class RecipientCreateTemplateRecipientsInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class RecipientCreateTemplateRecipientsInternalServerErrorIssue(BaseModel):
    message: str


class RecipientCreateTemplateRecipientsInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[
        List[RecipientCreateTemplateRecipientsInternalServerErrorIssue]
    ] = None


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

    data: RecipientCreateTemplateRecipientsInternalServerErrorData = field(hash=False)

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


class RecipientCreateTemplateRecipientsForbiddenIssue(BaseModel):
    message: str


class RecipientCreateTemplateRecipientsForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateTemplateRecipientsForbiddenIssue]] = None


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

    data: RecipientCreateTemplateRecipientsForbiddenErrorData = field(hash=False)

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


class RecipientCreateTemplateRecipientsUnauthorizedIssue(BaseModel):
    message: str


class RecipientCreateTemplateRecipientsUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateTemplateRecipientsUnauthorizedIssue]] = None


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

    data: RecipientCreateTemplateRecipientsUnauthorizedErrorData = field(hash=False)

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


class RecipientCreateTemplateRecipientsBadRequestIssue(BaseModel):
    message: str


class RecipientCreateTemplateRecipientsBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateTemplateRecipientsBadRequestIssue]] = None


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

    data: RecipientCreateTemplateRecipientsBadRequestErrorData = field(hash=False)

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


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


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


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


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


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


class RecipientCreateTemplateRecipientsAuthOptionsTypedDict(TypedDict):
    access_auth: List[RecipientCreateTemplateRecipientsAccessAuthResponse]
    action_auth: List[RecipientCreateTemplateRecipientsActionAuthResponse]


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

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


class RecipientCreateTemplateRecipientsRecipientResponseTypedDict(TypedDict):
    envelope_id: str
    role: RecipientCreateTemplateRecipientsRoleResponse
    read_status: RecipientCreateTemplateRecipientsReadStatus
    signing_status: RecipientCreateTemplateRecipientsSigningStatus
    send_status: RecipientCreateTemplateRecipientsSendStatus
    id: float
    email: str
    name: str
    token: str
    document_deleted_at: Nullable[str]
    expired: Nullable[str]
    signed_at: Nullable[str]
    auth_options: Nullable[RecipientCreateTemplateRecipientsAuthOptionsTypedDict]
    signing_order: Nullable[float]
    rejection_reason: Nullable[str]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

    role: RecipientCreateTemplateRecipientsRoleResponse

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

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

    send_status: Annotated[
        RecipientCreateTemplateRecipientsSendStatus, 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[RecipientCreateTemplateRecipientsAuthOptions],
        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 RecipientCreateTemplateRecipientsResponseTypedDict(TypedDict):
    r"""Successful response"""

    recipients: List[RecipientCreateTemplateRecipientsRecipientResponseTypedDict]


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

    recipients: List[RecipientCreateTemplateRecipientsRecipientResponse]
