"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from documenso_sdk import utils
from documenso_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from enum import Enum
import pydantic
from pydantic import model_serializer
from typing import List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


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


class RecipientCreateTemplateRecipientsAccessAuth(str, Enum):
    r"""The type of authentication required for the recipient to access the document."""

    ACCOUNT = "ACCOUNT"


class RecipientCreateTemplateRecipientsActionAuth(str, Enum):
    r"""The type of authentication required for the recipient to sign the document."""

    ACCOUNT = "ACCOUNT"
    PASSKEY = "PASSKEY"
    TWO_FACTOR_AUTH = "TWO_FACTOR_AUTH"
    EXPLICIT_NONE = "EXPLICIT_NONE"


class RecipientCreateTemplateRecipientsRecipientsTypedDict(TypedDict):
    email: str
    name: str
    role: RecipientCreateTemplateRecipientsRole
    signing_order: NotRequired[float]
    access_auth: NotRequired[Nullable[RecipientCreateTemplateRecipientsAccessAuth]]
    r"""The type of authentication required for the recipient to access the document."""
    action_auth: NotRequired[Nullable[RecipientCreateTemplateRecipientsActionAuth]]
    r"""The type of authentication required for the recipient to sign the document."""


class RecipientCreateTemplateRecipientsRecipients(BaseModel):
    email: str

    name: str

    role: RecipientCreateTemplateRecipientsRole

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

    access_auth: Annotated[
        OptionalNullable[RecipientCreateTemplateRecipientsAccessAuth],
        pydantic.Field(alias="accessAuth"),
    ] = UNSET
    r"""The type of authentication required for the recipient to access the document."""

    action_auth: Annotated[
        OptionalNullable[RecipientCreateTemplateRecipientsActionAuth],
        pydantic.Field(alias="actionAuth"),
    ] = UNSET
    r"""The type of authentication required for the recipient to sign the document."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["signingOrder", "accessAuth", "actionAuth"]
        nullable_fields = ["accessAuth", "actionAuth"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in 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 RecipientCreateTemplateRecipientsRequestBodyTypedDict(TypedDict):
    template_id: float
    recipients: List[RecipientCreateTemplateRecipientsRecipientsTypedDict]


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

    recipients: List[RecipientCreateTemplateRecipientsRecipients]


class RecipientCreateTemplateRecipientsTemplatesRecipientsIssuesTypedDict(TypedDict):
    message: str


class RecipientCreateTemplateRecipientsTemplatesRecipientsIssues(BaseModel):
    message: str


class RecipientCreateTemplateRecipientsTemplatesRecipientsResponseResponseBodyData(
    BaseModel
):
    message: str

    code: str

    issues: Optional[
        List[RecipientCreateTemplateRecipientsTemplatesRecipientsIssues]
    ] = None


class RecipientCreateTemplateRecipientsTemplatesRecipientsResponseResponseBody(
    Exception
):
    r"""Internal server error"""

    data: RecipientCreateTemplateRecipientsTemplatesRecipientsResponseResponseBodyData

    def __init__(
        self,
        data: RecipientCreateTemplateRecipientsTemplatesRecipientsResponseResponseBodyData,
    ):
        self.data = data

    def __str__(self) -> str:
        return utils.marshal_json(
            self.data,
            RecipientCreateTemplateRecipientsTemplatesRecipientsResponseResponseBodyData,
        )


class RecipientCreateTemplateRecipientsIssuesTypedDict(TypedDict):
    message: str


class RecipientCreateTemplateRecipientsIssues(BaseModel):
    message: str


class RecipientCreateTemplateRecipientsTemplatesRecipientsResponseBodyData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateTemplateRecipientsIssues]] = None


class RecipientCreateTemplateRecipientsTemplatesRecipientsResponseBody(Exception):
    r"""Invalid input data"""

    data: RecipientCreateTemplateRecipientsTemplatesRecipientsResponseBodyData

    def __init__(
        self, data: RecipientCreateTemplateRecipientsTemplatesRecipientsResponseBodyData
    ):
        self.data = data

    def __str__(self) -> str:
        return utils.marshal_json(
            self.data,
            RecipientCreateTemplateRecipientsTemplatesRecipientsResponseBodyData,
        )


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


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 RecipientCreateTemplateRecipientsTemplatesRecipientsAccessAuth(str, Enum):
    r"""The type of authentication required for the recipient to access the document."""

    ACCOUNT = "ACCOUNT"


class RecipientCreateTemplateRecipientsTemplatesRecipientsActionAuth(str, Enum):
    r"""The type of authentication required for the recipient to sign the document."""

    ACCOUNT = "ACCOUNT"
    PASSKEY = "PASSKEY"
    TWO_FACTOR_AUTH = "TWO_FACTOR_AUTH"
    EXPLICIT_NONE = "EXPLICIT_NONE"


class RecipientCreateTemplateRecipientsAuthOptionsTypedDict(TypedDict):
    access_auth: Nullable[
        RecipientCreateTemplateRecipientsTemplatesRecipientsAccessAuth
    ]
    r"""The type of authentication required for the recipient to access the document."""
    action_auth: Nullable[
        RecipientCreateTemplateRecipientsTemplatesRecipientsActionAuth
    ]
    r"""The type of authentication required for the recipient to sign the document."""


class RecipientCreateTemplateRecipientsAuthOptions(BaseModel):
    access_auth: Annotated[
        Nullable[RecipientCreateTemplateRecipientsTemplatesRecipientsAccessAuth],
        pydantic.Field(alias="accessAuth"),
    ]
    r"""The type of authentication required for the recipient to access the document."""

    action_auth: Annotated[
        Nullable[RecipientCreateTemplateRecipientsTemplatesRecipientsActionAuth],
        pydantic.Field(alias="actionAuth"),
    ]
    r"""The type of authentication required for the recipient to sign the document."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = []
        nullable_fields = ["accessAuth", "actionAuth"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in 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 RecipientCreateTemplateRecipientsTemplatesRecipientsRecipientsTypedDict(
    TypedDict
):
    role: RecipientCreateTemplateRecipientsTemplatesRecipientsRole
    read_status: RecipientCreateTemplateRecipientsReadStatus
    signing_status: RecipientCreateTemplateRecipientsSigningStatus
    send_status: RecipientCreateTemplateRecipientsSendStatus
    id: int
    document_id: Nullable[int]
    template_id: Nullable[int]
    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]
    r"""The order in which the recipient should sign the document. Only works if the document is set to sequential signing."""
    rejection_reason: Nullable[str]


class RecipientCreateTemplateRecipientsTemplatesRecipientsRecipients(BaseModel):
    role: RecipientCreateTemplateRecipientsTemplatesRecipientsRole

    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: int

    document_id: Annotated[Nullable[int], pydantic.Field(alias="documentId")]

    template_id: Annotated[Nullable[int], pydantic.Field(alias="templateId")]

    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")]
    r"""The order in which the recipient should sign the document. Only works if the document is set to sequential signing."""

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

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

        serialized = handler(self)

        m = {}

        for n, f in 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 RecipientCreateTemplateRecipientsResponseBodyTypedDict(TypedDict):
    r"""Successful response"""

    recipients: List[
        RecipientCreateTemplateRecipientsTemplatesRecipientsRecipientsTypedDict
    ]


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

    recipients: List[RecipientCreateTemplateRecipientsTemplatesRecipientsRecipients]
