"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .updatedocumentresponse import (
    UpdateDocumentResponse,
    UpdateDocumentResponseTypedDict,
)
from factify.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from factify.utils import FieldMetadata, PathParamMetadata, RequestMetadata
from pydantic import model_serializer
from typing import Dict, List
from typing_extensions import Annotated, NotRequired, TypedDict


class UpdateDocumentUpdateDocumentRequestTypedDict(TypedDict):
    r"""UpdateDocumentRequest specifies fields to update on a document."""

    description: NotRequired[Nullable[str]]
    r"""New description (max 2000 characters)."""
    title: NotRequired[Nullable[str]]
    r"""New title (1-255 characters)."""


class UpdateDocumentUpdateDocumentRequest(BaseModel):
    r"""UpdateDocumentRequest specifies fields to update on a document."""

    description: OptionalNullable[str] = UNSET
    r"""New description (max 2000 characters)."""

    title: OptionalNullable[str] = UNSET
    r"""New title (1-255 characters)."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["description", "title"])
        nullable_fields = set(["description", "title"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


class UpdateDocumentRequestTypedDict(TypedDict):
    document_id: str
    r"""Document ID to update."""
    body: UpdateDocumentUpdateDocumentRequestTypedDict


class UpdateDocumentRequest(BaseModel):
    document_id: Annotated[
        str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
    ]
    r"""Document ID to update."""

    body: Annotated[
        UpdateDocumentUpdateDocumentRequest,
        FieldMetadata(request=RequestMetadata(media_type="application/json")),
    ]


class UpdateDocumentResponseResponseTypedDict(TypedDict):
    headers: Dict[str, List[str]]
    result: UpdateDocumentResponseTypedDict


class UpdateDocumentResponseResponse(BaseModel):
    headers: Dict[str, List[str]]

    result: UpdateDocumentResponse
