"""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, TypedDict


class EnvelopeRedistributeRequestTypedDict(TypedDict):
    envelope_id: str
    recipients: List[float]


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

    recipients: List[float]


class EnvelopeRedistributeInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class EnvelopeRedistributeInternalServerErrorIssue(BaseModel):
    message: str


class EnvelopeRedistributeInternalServerErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[EnvelopeRedistributeInternalServerErrorIssue]] = None


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

    data: EnvelopeRedistributeInternalServerErrorData = field(hash=False)

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


class EnvelopeRedistributeForbiddenIssue(BaseModel):
    message: str


class EnvelopeRedistributeForbiddenErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[EnvelopeRedistributeForbiddenIssue]] = None


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

    data: EnvelopeRedistributeForbiddenErrorData = field(hash=False)

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


class EnvelopeRedistributeUnauthorizedIssue(BaseModel):
    message: str


class EnvelopeRedistributeUnauthorizedErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[EnvelopeRedistributeUnauthorizedIssue]] = None


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

    data: EnvelopeRedistributeUnauthorizedErrorData = field(hash=False)

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


class EnvelopeRedistributeBadRequestIssue(BaseModel):
    message: str


class EnvelopeRedistributeBadRequestErrorData(BaseModel):
    message: str
    code: str
    issues: Optional[List[EnvelopeRedistributeBadRequestIssue]] = None


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

    data: EnvelopeRedistributeBadRequestErrorData = field(hash=False)

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


class EnvelopeRedistributeRecipientTypedDict(TypedDict):
    id: float
    name: str
    email: str
    token: str
    role: EnvelopeRedistributeRole
    signing_order: Nullable[float]
    signing_url: str


class EnvelopeRedistributeRecipient(BaseModel):
    id: float

    name: str

    email: str

    token: str

    role: EnvelopeRedistributeRole

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

    signing_url: Annotated[str, pydantic.Field(alias="signingUrl")]

    @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 EnvelopeRedistributeResponseTypedDict(TypedDict):
    r"""Successful response"""

    success: bool
    id: str
    recipients: List[EnvelopeRedistributeRecipientTypedDict]


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

    success: bool

    id: str

    recipients: List[EnvelopeRedistributeRecipient]
