"""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 FolderUpdateFolderDataVisibility(str, Enum):
    EVERYONE = "EVERYONE"
    MANAGER_AND_ABOVE = "MANAGER_AND_ABOVE"
    ADMIN = "ADMIN"


class FolderUpdateFolderDataTypedDict(TypedDict):
    name: NotRequired[str]
    parent_id: NotRequired[Nullable[str]]
    visibility: NotRequired[FolderUpdateFolderDataVisibility]
    pinned: NotRequired[bool]


class FolderUpdateFolderData(BaseModel):
    name: Optional[str] = None

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

    visibility: Optional[FolderUpdateFolderDataVisibility] = None

    pinned: Optional[bool] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["name", "parentId", "visibility", "pinned"]
        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 FolderUpdateFolderRequestTypedDict(TypedDict):
    folder_id: str
    data: FolderUpdateFolderDataTypedDict


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

    data: FolderUpdateFolderData


class FolderUpdateFolderInternalServerErrorIssueTypedDict(TypedDict):
    message: str


class FolderUpdateFolderInternalServerErrorIssue(BaseModel):
    message: str


class FolderUpdateFolderInternalServerErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderUpdateFolderInternalServerErrorIssue]] = None


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

    data: FolderUpdateFolderInternalServerErrorData = field(hash=False)

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


class FolderUpdateFolderForbiddenIssue(BaseModel):
    message: str


class FolderUpdateFolderForbiddenErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderUpdateFolderForbiddenIssue]] = None


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

    data: FolderUpdateFolderForbiddenErrorData = field(hash=False)

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


class FolderUpdateFolderUnauthorizedIssue(BaseModel):
    message: str


class FolderUpdateFolderUnauthorizedErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderUpdateFolderUnauthorizedIssue]] = None


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

    data: FolderUpdateFolderUnauthorizedErrorData = field(hash=False)

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


class FolderUpdateFolderBadRequestIssue(BaseModel):
    message: str


class FolderUpdateFolderBadRequestErrorData(BaseModel):
    message: str

    code: str

    issues: Optional[List[FolderUpdateFolderBadRequestIssue]] = None


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

    data: FolderUpdateFolderBadRequestErrorData = field(hash=False)

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


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


class FolderUpdateFolderResponseTypedDict(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: FolderUpdateFolderVisibilityResponse
    type: FolderUpdateFolderType


class FolderUpdateFolderResponse(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: FolderUpdateFolderVisibilityResponse

    type: FolderUpdateFolderType

    @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
