"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
# @generated-id: eadbe3f9040c

from __future__ import annotations
from .embeddingdtype import EmbeddingDtype
from .encodingformat import EncodingFormat
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, List, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


EmbeddingRequestInputsTypedDict = TypeAliasType(
    "EmbeddingRequestInputsTypedDict", Union[str, List[str]]
)
r"""Text to embed."""


EmbeddingRequestInputs = TypeAliasType("EmbeddingRequestInputs", Union[str, List[str]])
r"""Text to embed."""


class EmbeddingRequestTypedDict(TypedDict):
    model: str
    r"""ID of the model to use."""
    inputs: EmbeddingRequestInputsTypedDict
    r"""Text to embed."""
    metadata: NotRequired[Nullable[Dict[str, Any]]]
    output_dimension: NotRequired[Nullable[int]]
    r"""The dimension of the output embeddings when feature available. If not provided, a default output dimension will be used."""
    output_dtype: NotRequired[EmbeddingDtype]
    encoding_format: NotRequired[EncodingFormat]


class EmbeddingRequest(BaseModel):
    model: str
    r"""ID of the model to use."""

    inputs: Annotated[EmbeddingRequestInputs, pydantic.Field(alias="input")]
    r"""Text to embed."""

    metadata: OptionalNullable[Dict[str, Any]] = UNSET

    output_dimension: OptionalNullable[int] = UNSET
    r"""The dimension of the output embeddings when feature available. If not provided, a default output dimension will be used."""

    output_dtype: Optional[EmbeddingDtype] = None

    encoding_format: Optional[EncodingFormat] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            ["metadata", "output_dimension", "output_dtype", "encoding_format"]
        )
        nullable_fields = set(["metadata", "output_dimension"])
        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


try:
    EmbeddingRequest.model_rebuild()
except NameError:
    pass
