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


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


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


class RecipientCreateDocumentRecipientRecipientTypedDict(TypedDict):
    email: str
    name: str
    role: RecipientCreateDocumentRecipientRoleRequest
    signing_order: NotRequired[float]
    access_auth: NotRequired[List[RecipientCreateDocumentRecipientAccessAuthRequest]]
    action_auth: NotRequired[List[RecipientCreateDocumentRecipientActionAuthRequest]]


class RecipientCreateDocumentRecipientRecipient(BaseModel):
    email: str

    name: str

    role: RecipientCreateDocumentRecipientRoleRequest

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

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

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


class RecipientCreateDocumentRecipientRequestTypedDict(TypedDict):
    document_id: float
    recipient: RecipientCreateDocumentRecipientRecipientTypedDict


class RecipientCreateDocumentRecipientRequest(BaseModel):
    document_id: Annotated[float, pydantic.Field(alias="documentId")]

    recipient: RecipientCreateDocumentRecipientRecipient


class RecipientCreateDocumentRecipientInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class RecipientCreateDocumentRecipientInternalServerErrorIssue(BaseModel):
    message: str


class RecipientCreateDocumentRecipientInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateDocumentRecipientInternalServerErrorIssue]] = (
        None
    )


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

    data: RecipientCreateDocumentRecipientInternalServerErrorData = field(hash=False)

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


class RecipientCreateDocumentRecipientForbiddenIssue(BaseModel):
    message: str


class RecipientCreateDocumentRecipientForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateDocumentRecipientForbiddenIssue]] = None


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

    data: RecipientCreateDocumentRecipientForbiddenErrorData = field(hash=False)

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


class RecipientCreateDocumentRecipientUnauthorizedIssue(BaseModel):
    message: str


class RecipientCreateDocumentRecipientUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateDocumentRecipientUnauthorizedIssue]] = None


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

    data: RecipientCreateDocumentRecipientUnauthorizedErrorData = field(hash=False)

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


class RecipientCreateDocumentRecipientBadRequestIssue(BaseModel):
    message: str


class RecipientCreateDocumentRecipientBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[RecipientCreateDocumentRecipientBadRequestIssue]] = None


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

    data: RecipientCreateDocumentRecipientBadRequestErrorData = field(hash=False)

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


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


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


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


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


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


class RecipientCreateDocumentRecipientAuthOptionsTypedDict(TypedDict):
    access_auth: List[RecipientCreateDocumentRecipientAccessAuthResponse]
    action_auth: List[RecipientCreateDocumentRecipientActionAuthResponse]


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

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


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

    envelope_id: str
    role: RecipientCreateDocumentRecipientRoleResponse
    read_status: RecipientCreateDocumentRecipientReadStatus
    signing_status: RecipientCreateDocumentRecipientSigningStatus
    send_status: RecipientCreateDocumentRecipientSendStatus
    id: float
    email: str
    name: str
    token: str
    document_deleted_at: Nullable[str]
    expired: Nullable[str]
    signed_at: Nullable[str]
    auth_options: Nullable[RecipientCreateDocumentRecipientAuthOptionsTypedDict]
    signing_order: Nullable[float]
    rejection_reason: Nullable[str]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

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

    role: RecipientCreateDocumentRecipientRoleResponse

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

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

    send_status: Annotated[
        RecipientCreateDocumentRecipientSendStatus, 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[RecipientCreateDocumentRecipientAuthOptions],
        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
