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


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


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


class EnvelopeRecipientUpdateManyDataRequestTypedDict(TypedDict):
    id: float
    email: NotRequired[str]
    name: NotRequired[str]
    role: NotRequired[EnvelopeRecipientUpdateManyRoleRequest]
    signing_order: NotRequired[float]
    access_auth: NotRequired[List[EnvelopeRecipientUpdateManyAccessAuthRequest]]
    action_auth: NotRequired[List[EnvelopeRecipientUpdateManyActionAuthRequest]]


class EnvelopeRecipientUpdateManyDataRequest(BaseModel):
    id: float

    email: Optional[str] = None

    name: Optional[str] = None

    role: Optional[EnvelopeRecipientUpdateManyRoleRequest] = None

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

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

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


class EnvelopeRecipientUpdateManyRequestTypedDict(TypedDict):
    envelope_id: str
    data: List[EnvelopeRecipientUpdateManyDataRequestTypedDict]


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

    data: List[EnvelopeRecipientUpdateManyDataRequest]


class EnvelopeRecipientUpdateManyInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class EnvelopeRecipientUpdateManyInternalServerErrorIssue(BaseModel):
    message: str


class EnvelopeRecipientUpdateManyInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientUpdateManyInternalServerErrorIssue]] = None


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

    data: EnvelopeRecipientUpdateManyInternalServerErrorData = field(hash=False)

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


class EnvelopeRecipientUpdateManyForbiddenIssue(BaseModel):
    message: str


class EnvelopeRecipientUpdateManyForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientUpdateManyForbiddenIssue]] = None


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

    data: EnvelopeRecipientUpdateManyForbiddenErrorData = field(hash=False)

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


class EnvelopeRecipientUpdateManyUnauthorizedIssue(BaseModel):
    message: str


class EnvelopeRecipientUpdateManyUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientUpdateManyUnauthorizedIssue]] = None


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

    data: EnvelopeRecipientUpdateManyUnauthorizedErrorData = field(hash=False)

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


class EnvelopeRecipientUpdateManyBadRequestIssue(BaseModel):
    message: str


class EnvelopeRecipientUpdateManyBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeRecipientUpdateManyBadRequestIssue]] = None


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

    data: EnvelopeRecipientUpdateManyBadRequestErrorData = field(hash=False)

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


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


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


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


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


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


class EnvelopeRecipientUpdateManyAuthOptionsTypedDict(TypedDict):
    access_auth: List[EnvelopeRecipientUpdateManyAccessAuthResponse]
    action_auth: List[EnvelopeRecipientUpdateManyActionAuthResponse]


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

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


class EnvelopeRecipientUpdateManyDataResponseTypedDict(TypedDict):
    envelope_id: str
    role: EnvelopeRecipientUpdateManyRoleResponse
    read_status: EnvelopeRecipientUpdateManyReadStatus
    signing_status: EnvelopeRecipientUpdateManySigningStatus
    send_status: EnvelopeRecipientUpdateManySendStatus
    id: float
    email: str
    name: str
    token: str
    document_deleted_at: Nullable[str]
    expired: Nullable[str]
    signed_at: Nullable[str]
    auth_options: Nullable[EnvelopeRecipientUpdateManyAuthOptionsTypedDict]
    signing_order: Nullable[float]
    rejection_reason: Nullable[str]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

    role: EnvelopeRecipientUpdateManyRoleResponse

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

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

    send_status: Annotated[
        EnvelopeRecipientUpdateManySendStatus, 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[EnvelopeRecipientUpdateManyAuthOptions],
        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 EnvelopeRecipientUpdateManyResponseTypedDict(TypedDict):
    r"""Successful response"""

    data: List[EnvelopeRecipientUpdateManyDataResponseTypedDict]


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

    data: List[EnvelopeRecipientUpdateManyDataResponse]
