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


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


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


class EnvelopeRecipientCreateManyDataRequestTypedDict(TypedDict):
    email: str
    name: str
    role: EnvelopeRecipientCreateManyRoleRequest
    signing_order: NotRequired[float]
    access_auth: NotRequired[List[EnvelopeRecipientCreateManyAccessAuthRequest]]
    action_auth: NotRequired[List[EnvelopeRecipientCreateManyActionAuthRequest]]


class EnvelopeRecipientCreateManyDataRequest(BaseModel):
    email: str

    name: str

    role: EnvelopeRecipientCreateManyRoleRequest

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

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

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


class EnvelopeRecipientCreateManyRequestTypedDict(TypedDict):
    envelope_id: str
    data: List[EnvelopeRecipientCreateManyDataRequestTypedDict]


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

    data: List[EnvelopeRecipientCreateManyDataRequest]


class EnvelopeRecipientCreateManyInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class EnvelopeRecipientCreateManyInternalServerErrorIssue(BaseModel):
    message: str


class EnvelopeRecipientCreateManyInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientCreateManyInternalServerErrorIssue]] = None


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

    data: EnvelopeRecipientCreateManyInternalServerErrorData = field(hash=False)

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


class EnvelopeRecipientCreateManyForbiddenIssue(BaseModel):
    message: str


class EnvelopeRecipientCreateManyForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientCreateManyForbiddenIssue]] = None


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

    data: EnvelopeRecipientCreateManyForbiddenErrorData = field(hash=False)

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


class EnvelopeRecipientCreateManyUnauthorizedIssue(BaseModel):
    message: str


class EnvelopeRecipientCreateManyUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientCreateManyUnauthorizedIssue]] = None


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

    data: EnvelopeRecipientCreateManyUnauthorizedErrorData = field(hash=False)

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


class EnvelopeRecipientCreateManyBadRequestIssue(BaseModel):
    message: str


class EnvelopeRecipientCreateManyBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientCreateManyBadRequestIssue]] = None


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

    data: EnvelopeRecipientCreateManyBadRequestErrorData = field(hash=False)

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


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


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


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


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


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


class EnvelopeRecipientCreateManyAuthOptionsTypedDict(TypedDict):
    access_auth: List[EnvelopeRecipientCreateManyAccessAuthResponse]
    action_auth: List[EnvelopeRecipientCreateManyActionAuthResponse]


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

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


class EnvelopeRecipientCreateManyDataResponseTypedDict(TypedDict):
    envelope_id: str
    role: EnvelopeRecipientCreateManyRoleResponse
    read_status: EnvelopeRecipientCreateManyReadStatus
    signing_status: EnvelopeRecipientCreateManySigningStatus
    send_status: EnvelopeRecipientCreateManySendStatus
    id: float
    email: str
    name: str
    token: str
    document_deleted_at: Nullable[str]
    expired: Nullable[str]
    signed_at: Nullable[str]
    auth_options: Nullable[EnvelopeRecipientCreateManyAuthOptionsTypedDict]
    signing_order: Nullable[float]
    rejection_reason: Nullable[str]


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

    role: EnvelopeRecipientCreateManyRoleResponse

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

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

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

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

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = []
        nullable_fields = [
            "documentDeletedAt",
            "expired",
            "signedAt",
            "authOptions",
            "signingOrder",
            "rejectionReason",
        ]
        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 EnvelopeRecipientCreateManyResponseTypedDict(TypedDict):
    r"""Successful response"""

    data: List[EnvelopeRecipientCreateManyDataResponseTypedDict]


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

    data: List[EnvelopeRecipientCreateManyDataResponse]
