"""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 documenso_sdk.utils import FieldMetadata, QueryParamMetadata
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 FolderFindFoldersQueryParamType(str, Enum):
    DOCUMENT = "DOCUMENT"
    TEMPLATE = "TEMPLATE"


class FolderFindFoldersRequestTypedDict(TypedDict):
    query: NotRequired[str]
    r"""The search query."""
    page: NotRequired[float]
    r"""The pagination page number, starts at 1."""
    per_page: NotRequired[float]
    r"""The number of items per page."""
    parent_id: NotRequired[str]
    type: NotRequired[FolderFindFoldersQueryParamType]


class FolderFindFoldersRequest(BaseModel):
    query: Annotated[
        Optional[str],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The search query."""

    page: Annotated[
        Optional[float],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The pagination page number, starts at 1."""

    per_page: Annotated[
        Optional[float],
        pydantic.Field(alias="perPage"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None
    r"""The number of items per page."""

    parent_id: Annotated[
        Optional[str],
        pydantic.Field(alias="parentId"),
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None

    type: Annotated[
        Optional[FolderFindFoldersQueryParamType],
        FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
    ] = None


class FolderFindFoldersInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class FolderFindFoldersInternalServerErrorIssue(BaseModel):
    message: str


class FolderFindFoldersInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderFindFoldersInternalServerErrorIssue]] = None


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

    data: FolderFindFoldersInternalServerErrorData = field(hash=False)

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


class FolderFindFoldersNotFoundIssue(BaseModel):
    message: str


class FolderFindFoldersNotFoundErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderFindFoldersNotFoundIssue]] = None


@dataclass(unsafe_hash=True)
class FolderFindFoldersNotFoundError(DocumensoError):
    r"""Not found"""

    data: FolderFindFoldersNotFoundErrorData = field(hash=False)

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


class FolderFindFoldersForbiddenIssue(BaseModel):
    message: str


class FolderFindFoldersForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderFindFoldersForbiddenIssue]] = None


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

    data: FolderFindFoldersForbiddenErrorData = field(hash=False)

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


class FolderFindFoldersUnauthorizedIssue(BaseModel):
    message: str


class FolderFindFoldersUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderFindFoldersUnauthorizedIssue]] = None


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

    data: FolderFindFoldersUnauthorizedErrorData = field(hash=False)

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


class FolderFindFoldersBadRequestIssue(BaseModel):
    message: str


class FolderFindFoldersBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderFindFoldersBadRequestIssue]] = None


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

    data: FolderFindFoldersBadRequestErrorData = field(hash=False)

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


class FolderFindFoldersDataType(str, Enum):
    DOCUMENT = "DOCUMENT"
    TEMPLATE = "TEMPLATE"


class FolderFindFoldersDataTypedDict(TypedDict):
    id: str
    name: str
    user_id: float
    team_id: float
    parent_id: Nullable[str]
    pinned: bool
    created_at: str
    updated_at: str
    visibility: FolderFindFoldersVisibility
    type: FolderFindFoldersDataType


class FolderFindFoldersData(BaseModel):
    id: str

    name: str

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

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

    parent_id: Annotated[Nullable[str], pydantic.Field(alias="parentId")]

    pinned: bool

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

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

    visibility: FolderFindFoldersVisibility

    type: FolderFindFoldersDataType

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = []
        nullable_fields = ["parentId"]
        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 FolderFindFoldersResponseTypedDict(TypedDict):
    r"""Successful response"""

    data: List[FolderFindFoldersDataTypedDict]
    count: float
    current_page: float
    per_page: float
    total_pages: float


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

    data: List[FolderFindFoldersData]

    count: float

    current_page: Annotated[float, pydantic.Field(alias="currentPage")]

    per_page: Annotated[float, pydantic.Field(alias="perPage")]

    total_pages: Annotated[float, pydantic.Field(alias="totalPages")]
