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

from __future__ import annotations
from .fieldsselector_union import FieldsSelectorUnion, FieldsSelectorUnionTypedDict
from .partitionfilter import PartitionFilter, PartitionFilterTypedDict
from lambdadb.types import BaseModel, UNSET_SENTINEL
from lambdadb.utils import FieldMetadata, PathParamMetadata, RequestMetadata
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, List, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class FetchDocsRequestBodyTypedDict(TypedDict):
    ids: List[str]
    r"""A list of document IDs to fetch. Note that the maximum number of document IDs is 100."""
    consistent_read: NotRequired[bool]
    r"""If your application requires a strongly consistent read, set consistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value."""
    include_vectors: NotRequired[bool]
    r"""If your application need to include vector values in the response, set includeVectors to true."""
    fields: NotRequired[FieldsSelectorUnionTypedDict]
    r"""An object to specify a list of field names to include and/or exclude in the result."""
    partition_filter: NotRequired[PartitionFilterTypedDict]


class FetchDocsRequestBody(BaseModel):
    ids: List[str]
    r"""A list of document IDs to fetch. Note that the maximum number of document IDs is 100."""

    consistent_read: Annotated[
        Optional[bool], pydantic.Field(alias="consistentRead")
    ] = False
    r"""If your application requires a strongly consistent read, set consistentRead to true. Although a strongly consistent read might take more time than an eventually consistent read, it always returns the last updated value."""

    include_vectors: Annotated[
        Optional[bool], pydantic.Field(alias="includeVectors")
    ] = False
    r"""If your application need to include vector values in the response, set includeVectors to true."""

    fields: Optional[FieldsSelectorUnion] = None
    r"""An object to specify a list of field names to include and/or exclude in the result."""

    partition_filter: Annotated[
        Optional[PartitionFilter], pydantic.Field(alias="partitionFilter")
    ] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["consistentRead", "includeVectors", "fields", "partitionFilter"]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

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

        return m


class FetchDocsRequestTypedDict(TypedDict):
    collection_name: str
    r"""Collection name."""
    request_body: FetchDocsRequestBodyTypedDict


class FetchDocsRequest(BaseModel):
    collection_name: Annotated[
        str,
        pydantic.Field(alias="collectionName"),
        FieldMetadata(path=PathParamMetadata(style="simple", explode=False)),
    ]
    r"""Collection name."""

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


class FetchDocsDocTypedDict(TypedDict):
    collection: str
    doc: Dict[str, Any]


class FetchDocsDoc(BaseModel):
    collection: str

    doc: Dict[str, Any]


class FetchDocsResponseTypedDict(TypedDict):
    r"""Fetched documents."""

    total: int
    r"""Total number of documents returned."""
    took: int
    r"""Elapsed time in milliseconds."""
    docs: List[FetchDocsDocTypedDict]
    is_docs_inline: bool
    r"""Whether the list of documents is included."""
    docs_url: NotRequired[str]
    r"""Download URL for the list of documents."""


class FetchDocsResponse(BaseModel):
    r"""Fetched documents."""

    total: int
    r"""Total number of documents returned."""

    took: int
    r"""Elapsed time in milliseconds."""

    docs: List[FetchDocsDoc]

    is_docs_inline: Annotated[bool, pydantic.Field(alias="isDocsInline")]
    r"""Whether the list of documents is included."""

    docs_url: Annotated[Optional[str], pydantic.Field(alias="docsUrl")] = None
    r"""Download URL for the list of documents."""

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

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

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

        return m
