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

from __future__ import annotations
from .indexconfigs_union import IndexConfigsUnion, IndexConfigsUnionTypedDict
from .partitionconfig import PartitionConfig, PartitionConfigTypedDict
from .status import Status
from lambdadb.types import BaseModel, UNSET_SENTINEL
import pydantic
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class CollectionResponseTypedDict(TypedDict):
    project_name: str
    r"""Project name."""
    collection_name: str
    r"""Collection name."""
    index_configs: Dict[str, IndexConfigsUnionTypedDict]
    num_partitions: int
    r"""Total number of partitions including the default partition."""
    num_docs: int
    r"""Total number of documents."""
    collection_status: Status
    r"""Status"""
    partition_config: NotRequired[PartitionConfigTypedDict]
    source_project_name: NotRequired[str]
    r"""Source project name."""
    source_collection_name: NotRequired[str]
    r"""Source collection name."""
    source_collection_version_id: NotRequired[str]
    r"""Source collection version."""


class CollectionResponse(BaseModel):
    project_name: Annotated[str, pydantic.Field(alias="projectName")]
    r"""Project name."""

    collection_name: Annotated[str, pydantic.Field(alias="collectionName")]
    r"""Collection name."""

    index_configs: Annotated[
        Dict[str, IndexConfigsUnion], pydantic.Field(alias="indexConfigs")
    ]

    num_partitions: Annotated[int, pydantic.Field(alias="numPartitions")]
    r"""Total number of partitions including the default partition."""

    num_docs: Annotated[int, pydantic.Field(alias="numDocs")]
    r"""Total number of documents."""

    collection_status: Annotated[Status, pydantic.Field(alias="collectionStatus")]
    r"""Status"""

    partition_config: Annotated[
        Optional[PartitionConfig], pydantic.Field(alias="partitionConfig")
    ] = None

    source_project_name: Annotated[
        Optional[str], pydantic.Field(alias="sourceProjectName")
    ] = None
    r"""Source project name."""

    source_collection_name: Annotated[
        Optional[str], pydantic.Field(alias="sourceCollectionName")
    ] = None
    r"""Source collection name."""

    source_collection_version_id: Annotated[
        Optional[str], pydantic.Field(alias="sourceCollectionVersionId")
    ] = None
    r"""Source collection version."""

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