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


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


class FolderCreateFolderRequestTypedDict(TypedDict):
    name: str
    parent_id: NotRequired[str]
    type: NotRequired[FolderCreateFolderTypeRequest]


class FolderCreateFolderRequest(BaseModel):
    name: str

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

    type: Optional[FolderCreateFolderTypeRequest] = None


class FolderCreateFolderInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class FolderCreateFolderInternalServerErrorIssue(BaseModel):
    message: str


class FolderCreateFolderInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderCreateFolderInternalServerErrorIssue]] = None


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

    data: FolderCreateFolderInternalServerErrorData = field(hash=False)

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


class FolderCreateFolderForbiddenIssue(BaseModel):
    message: str


class FolderCreateFolderForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderCreateFolderForbiddenIssue]] = None


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

    data: FolderCreateFolderForbiddenErrorData = field(hash=False)

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


class FolderCreateFolderUnauthorizedIssue(BaseModel):
    message: str


class FolderCreateFolderUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderCreateFolderUnauthorizedIssue]] = None


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

    data: FolderCreateFolderUnauthorizedErrorData = field(hash=False)

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


class FolderCreateFolderBadRequestIssue(BaseModel):
    message: str


class FolderCreateFolderBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderCreateFolderBadRequestIssue]] = None


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

    data: FolderCreateFolderBadRequestErrorData = field(hash=False)

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


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


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

    id: str
    name: str
    user_id: float
    team_id: float
    parent_id: Nullable[str]
    pinned: bool
    created_at: str
    updated_at: str
    visibility: FolderCreateFolderVisibility
    type: FolderCreateFolderTypeResponse


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

    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: FolderCreateFolderVisibility

    type: FolderCreateFolderTypeResponse

    @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
