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

from __future__ import annotations
from duckyai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Any, Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DocumentTypedDict(TypedDict):
    doc_id: str
    r"""The unique identifier of the document"""
    content_chunks: List[str]
    next_cursor: NotRequired[Nullable[str]]
    r"""A cursor to fetch the next set of chunks (if available)"""
    metadata: NotRequired[Dict[str, Any]]
    r"""Metadata associated with the document. Accepts key value pairs where the value can be a string, number, boolean, or list of strings."""
    title: NotRequired[str]
    r"""Title of the document"""
    source_url: NotRequired[Nullable[str]]
    r"""URL associated with the document"""
    status: NotRequired[str]
    r"""Status of the document (pending, indexing, indexed)"""


class Document(BaseModel):
    doc_id: str
    r"""The unique identifier of the document"""

    content_chunks: List[str]

    next_cursor: OptionalNullable[str] = UNSET
    r"""A cursor to fetch the next set of chunks (if available)"""

    metadata: Optional[Dict[str, Any]] = None
    r"""Metadata associated with the document. Accepts key value pairs where the value can be a string, number, boolean, or list of strings."""

    title: Optional[str] = None
    r"""Title of the document"""

    source_url: OptionalNullable[str] = UNSET
    r"""URL associated with the document"""

    status: Optional[str] = None
    r"""Status of the document (pending, indexing, indexed)"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["next_cursor", "metadata", "title", "source_url", "status"]
        nullable_fields = ["next_cursor", "source_url"]
        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
