"""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 Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


class DocumentGetManyRequestTypedDict(TypedDict):
    document_ids: List[float]


class DocumentGetManyRequest(BaseModel):
    document_ids: Annotated[List[float], pydantic.Field(alias="documentIds")]


class DocumentGetManyInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class DocumentGetManyInternalServerErrorIssue(BaseModel):
    message: str


class DocumentGetManyInternalServerErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[DocumentGetManyInternalServerErrorIssue]] = None


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

    data: DocumentGetManyInternalServerErrorData = field(hash=False)

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


class DocumentGetManyForbiddenIssue(BaseModel):
    message: str


class DocumentGetManyForbiddenErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[DocumentGetManyForbiddenIssue]] = None


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

    data: DocumentGetManyForbiddenErrorData = field(hash=False)

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


class DocumentGetManyUnauthorizedIssue(BaseModel):
    message: str


class DocumentGetManyUnauthorizedErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[DocumentGetManyUnauthorizedIssue]] = None


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

    data: DocumentGetManyUnauthorizedErrorData = field(hash=False)

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


class DocumentGetManyBadRequestIssue(BaseModel):
    message: str


class DocumentGetManyBadRequestErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[DocumentGetManyBadRequestIssue]] = None


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

    data: DocumentGetManyBadRequestErrorData = field(hash=False)

    def __init__(
        self,
        data: DocumentGetManyBadRequestErrorData,
        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 DocumentGetManyVisibility(str, Enum):
    EVERYONE = "EVERYONE"
    MANAGER_AND_ABOVE = "MANAGER_AND_ABOVE"
    ADMIN = "ADMIN"


class DocumentGetManyStatus(str, Enum):
    DRAFT = "DRAFT"
    PENDING = "PENDING"
    COMPLETED = "COMPLETED"
    REJECTED = "REJECTED"


class DocumentGetManySource(str, Enum):
    DOCUMENT = "DOCUMENT"
    TEMPLATE = "TEMPLATE"
    TEMPLATE_DIRECT_LINK = "TEMPLATE_DIRECT_LINK"


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


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


class DocumentGetManyAuthOptionsTypedDict(TypedDict):
    global_access_auth: List[DocumentGetManyGlobalAccessAuth]
    global_action_auth: List[DocumentGetManyGlobalActionAuth]


class DocumentGetManyAuthOptions(BaseModel):
    global_access_auth: Annotated[
        List[DocumentGetManyGlobalAccessAuth], pydantic.Field(alias="globalAccessAuth")
    ]

    global_action_auth: Annotated[
        List[DocumentGetManyGlobalActionAuth], pydantic.Field(alias="globalActionAuth")
    ]


DocumentGetManyFormValuesTypedDict = TypeAliasType(
    "DocumentGetManyFormValuesTypedDict", Union[str, bool, float]
)


DocumentGetManyFormValues = TypeAliasType(
    "DocumentGetManyFormValues", Union[str, bool, float]
)


class DocumentGetManyUserTypedDict(TypedDict):
    id: float
    name: Nullable[str]
    email: str


class DocumentGetManyUser(BaseModel):
    id: float

    name: Nullable[str]

    email: str

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                m[k] = val

        return m


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


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


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


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


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


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


class DocumentGetManyRecipientAuthOptionsTypedDict(TypedDict):
    access_auth: List[DocumentGetManyAccessAuth]
    action_auth: List[DocumentGetManyActionAuth]


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

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


class DocumentGetManyRecipientTypedDict(TypedDict):
    envelope_id: str
    role: DocumentGetManyRole
    read_status: DocumentGetManyReadStatus
    signing_status: DocumentGetManySigningStatus
    send_status: DocumentGetManySendStatus
    id: float
    email: str
    name: str
    token: str
    document_deleted_at: Nullable[str]
    expired: Nullable[str]
    signed_at: Nullable[str]
    auth_options: Nullable[DocumentGetManyRecipientAuthOptionsTypedDict]
    signing_order: Nullable[float]
    rejection_reason: Nullable[str]
    document_id: NotRequired[Nullable[float]]
    template_id: NotRequired[Nullable[float]]


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

    role: DocumentGetManyRole

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

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

    send_status: Annotated[
        DocumentGetManySendStatus, 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[DocumentGetManyRecipientAuthOptions],
        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 = set(["documentId", "templateId"])
        nullable_fields = set(
            [
                "documentDeletedAt",
                "expired",
                "signedAt",
                "authOptions",
                "signingOrder",
                "rejectionReason",
                "documentId",
                "templateId",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


class DocumentGetManyTeamTypedDict(TypedDict):
    id: float
    url: str


class DocumentGetManyTeam(BaseModel):
    id: float

    url: str


class DocumentGetManyDataTypedDict(TypedDict):
    visibility: DocumentGetManyVisibility
    status: DocumentGetManyStatus
    source: DocumentGetManySource
    id: float
    external_id: Nullable[str]
    user_id: float
    auth_options: Nullable[DocumentGetManyAuthOptionsTypedDict]
    form_values: Nullable[Dict[str, DocumentGetManyFormValuesTypedDict]]
    title: str
    created_at: str
    updated_at: str
    completed_at: Nullable[str]
    deleted_at: Nullable[str]
    team_id: float
    folder_id: Nullable[str]
    use_legacy_field_insertion: bool
    envelope_id: str
    internal_version: float
    user: DocumentGetManyUserTypedDict
    recipients: List[DocumentGetManyRecipientTypedDict]
    team: Nullable[DocumentGetManyTeamTypedDict]
    document_data_id: NotRequired[str]
    template_id: NotRequired[Nullable[float]]


class DocumentGetManyData(BaseModel):
    visibility: DocumentGetManyVisibility

    status: DocumentGetManyStatus

    source: DocumentGetManySource

    id: float

    external_id: Annotated[Nullable[str], pydantic.Field(alias="externalId")]

    user_id: Annotated[float, pydantic.Field(alias="userId")]

    auth_options: Annotated[
        Nullable[DocumentGetManyAuthOptions], pydantic.Field(alias="authOptions")
    ]

    form_values: Annotated[
        Nullable[Dict[str, DocumentGetManyFormValues]],
        pydantic.Field(alias="formValues"),
    ]

    title: str

    created_at: Annotated[str, pydantic.Field(alias="createdAt")]

    updated_at: Annotated[str, pydantic.Field(alias="updatedAt")]

    completed_at: Annotated[Nullable[str], pydantic.Field(alias="completedAt")]

    deleted_at: Annotated[Nullable[str], pydantic.Field(alias="deletedAt")]

    team_id: Annotated[float, pydantic.Field(alias="teamId")]

    folder_id: Annotated[Nullable[str], pydantic.Field(alias="folderId")]

    use_legacy_field_insertion: Annotated[
        bool, pydantic.Field(alias="useLegacyFieldInsertion")
    ]

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

    internal_version: Annotated[float, pydantic.Field(alias="internalVersion")]

    user: DocumentGetManyUser

    recipients: List[DocumentGetManyRecipient]

    team: Nullable[DocumentGetManyTeam]

    document_data_id: Annotated[
        Optional[str], pydantic.Field(alias="documentDataId")
    ] = ""

    template_id: Annotated[
        OptionalNullable[float], pydantic.Field(alias="templateId")
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["documentDataId", "templateId"])
        nullable_fields = set(
            [
                "externalId",
                "authOptions",
                "formValues",
                "completedAt",
                "deletedAt",
                "folderId",
                "templateId",
                "team",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


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

    data: List[DocumentGetManyDataTypedDict]


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

    data: List[DocumentGetManyData]
