"""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 QueryCollectionRequestBodyTypedDict(TypedDict):
    query: Dict[str, Any]
    r"""Query object."""
    size: NotRequired[int]
    r"""Number of documents to return. Note that the maximum number of documents 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."""
    sort: NotRequired[List[Dict[str, Any]]]
    r"""List of field name, sort direction pairs."""
    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 QueryCollectionRequestBody(BaseModel):
    query: Dict[str, Any]
    r"""Query object."""

    size: Optional[int] = None
    r"""Number of documents to return. Note that the maximum number of documents 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."""

    sort: Optional[List[Dict[str, Any]]] = None
    r"""List of field name, sort direction pairs."""

    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(
            [
                "size",
                "consistentRead",
                "includeVectors",
                "sort",
                "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 QueryCollectionRequestTypedDict(TypedDict):
    collection_name: str
    r"""Collection name."""
    request_body: QueryCollectionRequestBodyTypedDict


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

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


class QueryCollectionDocTypedDict(TypedDict):
    collection: str
    r"""Collection name."""
    doc: Dict[str, Any]
    score: NotRequired[float]
    r"""Document similarity score."""


class QueryCollectionDoc(BaseModel):
    collection: str
    r"""Collection name."""

    doc: Dict[str, Any]

    score: Optional[float] = None
    r"""Document similarity score."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["score"])
        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 QueryCollectionResponseTypedDict(TypedDict):
    r"""Documents selected by query."""

    took: int
    r"""Elapsed time in milliseconds."""
    total: int
    r"""Total number of documents returned."""
    docs: List[QueryCollectionDocTypedDict]
    r"""List of documents."""
    is_docs_inline: bool
    r"""Whether the list of documents is included."""
    max_score: NotRequired[float]
    r"""Maximum score."""
    docs_url: NotRequired[str]
    r"""Optional download URL for the list of documents."""


class QueryCollectionResponse(BaseModel):
    r"""Documents selected by query."""

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

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

    docs: List[QueryCollectionDoc]
    r"""List of documents."""

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

    max_score: Annotated[Optional[float], pydantic.Field(alias="maxScore")] = None
    r"""Maximum score."""

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["maxScore", "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
