"""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 EnvelopeDistributeDateFormat(str, Enum):
    YYYY_M_MDD_HH_MM_A = "yyyy-MM-dd hh:mm a"
    YYYY_M_MDD = "yyyy-MM-dd"
    DD_MM_SLASH_YYYY = "dd/MM/yyyy"
    MM_DD_SLASH_YYYY = "MM/dd/yyyy"
    YY_M_MDD = "yy-MM-dd"
    MMMM_DD_COMMA_YYYY = "MMMM dd, yyyy"
    EEEE_MMMM_DD_COMMA_YYYY = "EEEE, MMMM dd, yyyy"
    DD_MM_SLASH_YYYY_HH_MM_A = "dd/MM/yyyy hh:mm a"
    DD_MM_SLASH_YYYY_H_HMM = "dd/MM/yyyy HH:mm"
    MM_DD_SLASH_YYYY_HH_MM_A = "MM/dd/yyyy hh:mm a"
    MM_DD_SLASH_YYYY_H_HMM = "MM/dd/yyyy HH:mm"
    DD_DOT_MM_DOT_YYYY = "dd.MM.yyyy"
    DD_DOT_MM_DOT_YYYY_H_HMM = "dd.MM.yyyy HH:mm"
    YYYY_M_MDD_H_HMM = "yyyy-MM-dd HH:mm"
    YY_M_MDD_HH_MM_A = "yy-MM-dd hh:mm a"
    YY_M_MDD_H_HMM = "yy-MM-dd HH:mm"
    YYYY_M_MDD_H_HMMSS = "yyyy-MM-dd HH:mm:ss"
    MMMM_DD_COMMA_YYYY_HH_MM_A = "MMMM dd, yyyy hh:mm a"
    MMMM_DD_COMMA_YYYY_H_HMM = "MMMM dd, yyyy HH:mm"
    EEEE_MMMM_DD_COMMA_YYYY_HH_MM_A = "EEEE, MMMM dd, yyyy hh:mm a"
    EEEE_MMMM_DD_COMMA_YYYY_H_HMM = "EEEE, MMMM dd, yyyy HH:mm"
    ISO8601_FULL = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"


class EnvelopeDistributeDistributionMethod(str, Enum):
    EMAIL = "EMAIL"
    NONE = "NONE"


class EnvelopeDistributeLanguage(str, Enum):
    DE = "de"
    EN = "en"
    FR = "fr"
    ES = "es"
    IT = "it"
    PL = "pl"


class EnvelopeDistributeEmailSettingsTypedDict(TypedDict):
    recipient_signing_request: NotRequired[bool]
    recipient_removed: NotRequired[bool]
    recipient_signed: NotRequired[bool]
    document_pending: NotRequired[bool]
    document_completed: NotRequired[bool]
    document_deleted: NotRequired[bool]
    owner_document_completed: NotRequired[bool]


class EnvelopeDistributeEmailSettings(BaseModel):
    recipient_signing_request: Annotated[
        Optional[bool], pydantic.Field(alias="recipientSigningRequest")
    ] = True

    recipient_removed: Annotated[
        Optional[bool], pydantic.Field(alias="recipientRemoved")
    ] = True

    recipient_signed: Annotated[
        Optional[bool], pydantic.Field(alias="recipientSigned")
    ] = True

    document_pending: Annotated[
        Optional[bool], pydantic.Field(alias="documentPending")
    ] = True

    document_completed: Annotated[
        Optional[bool], pydantic.Field(alias="documentCompleted")
    ] = True

    document_deleted: Annotated[
        Optional[bool], pydantic.Field(alias="documentDeleted")
    ] = True

    owner_document_completed: Annotated[
        Optional[bool], pydantic.Field(alias="ownerDocumentCompleted")
    ] = True


class EnvelopeDistributeMetaTypedDict(TypedDict):
    subject: NotRequired[str]
    message: NotRequired[str]
    timezone: NotRequired[str]
    date_format: NotRequired[EnvelopeDistributeDateFormat]
    distribution_method: NotRequired[EnvelopeDistributeDistributionMethod]
    redirect_url: NotRequired[str]
    language: NotRequired[EnvelopeDistributeLanguage]
    email_id: NotRequired[Nullable[str]]
    email_reply_to: NotRequired[Nullable[str]]
    email_settings: NotRequired[Nullable[EnvelopeDistributeEmailSettingsTypedDict]]


class EnvelopeDistributeMeta(BaseModel):
    subject: Optional[str] = None

    message: Optional[str] = None

    timezone: Optional[str] = None

    date_format: Annotated[
        Optional[EnvelopeDistributeDateFormat], pydantic.Field(alias="dateFormat")
    ] = None

    distribution_method: Annotated[
        Optional[EnvelopeDistributeDistributionMethod],
        pydantic.Field(alias="distributionMethod"),
    ] = None

    redirect_url: Annotated[Optional[str], pydantic.Field(alias="redirectUrl")] = None

    language: Optional[EnvelopeDistributeLanguage] = None

    email_id: Annotated[OptionalNullable[str], pydantic.Field(alias="emailId")] = UNSET

    email_reply_to: Annotated[
        OptionalNullable[str], pydantic.Field(alias="emailReplyTo")
    ] = UNSET

    email_settings: Annotated[
        OptionalNullable[EnvelopeDistributeEmailSettings],
        pydantic.Field(alias="emailSettings"),
    ] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = [
            "subject",
            "message",
            "timezone",
            "dateFormat",
            "distributionMethod",
            "redirectUrl",
            "language",
            "emailId",
            "emailReplyTo",
            "emailSettings",
        ]
        nullable_fields = ["emailId", "emailReplyTo", "emailSettings"]
        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 EnvelopeDistributeRequestTypedDict(TypedDict):
    envelope_id: str
    meta: NotRequired[EnvelopeDistributeMetaTypedDict]


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

    meta: Optional[EnvelopeDistributeMeta] = None


class EnvelopeDistributeInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class EnvelopeDistributeInternalServerErrorIssue(BaseModel):
    message: str


class EnvelopeDistributeInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeDistributeInternalServerErrorIssue]] = None


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

    data: EnvelopeDistributeInternalServerErrorData = field(hash=False)

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


class EnvelopeDistributeForbiddenIssue(BaseModel):
    message: str


class EnvelopeDistributeForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeDistributeForbiddenIssue]] = None


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

    data: EnvelopeDistributeForbiddenErrorData = field(hash=False)

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


class EnvelopeDistributeUnauthorizedIssue(BaseModel):
    message: str


class EnvelopeDistributeUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeDistributeUnauthorizedIssue]] = None


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

    data: EnvelopeDistributeUnauthorizedErrorData = field(hash=False)

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


class EnvelopeDistributeBadRequestIssue(BaseModel):
    message: str


class EnvelopeDistributeBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[EnvelopeDistributeBadRequestIssue]] = None


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

    data: EnvelopeDistributeBadRequestErrorData = field(hash=False)

    def __init__(
        self,
        data: EnvelopeDistributeBadRequestErrorData,
        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 EnvelopeDistributeResponseTypedDict(TypedDict):
    r"""Successful response"""

    success: bool


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

    success: bool
