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

from __future__ import annotations
from .tmodel import TModel, TModelTypedDict
from opperai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from pydantic import model_serializer
from typing import List, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


InputTypedDict = TypeAliasType("InputTypedDict", Union[str, List[str]])
r"""The input to embed, can be a single string or a list of strings"""


Input = TypeAliasType("Input", Union[str, List[str]])
r"""The input to embed, can be a single string or a list of strings"""


class CreateEmbeddingRequestTypedDict(TypedDict):
    input: InputTypedDict
    r"""The input to embed, can be a single string or a list of strings"""
    model: NotRequired[Nullable[TModelTypedDict]]
    r"""The model to use for the embedding, if not provided, `EmbeddingModel(hosting_provider='Azure', location='EU', identifier='azure/text-embedding-3-large', name='azure/text-embedding-3-large-1536', dimensions=1536, max_tokens=8191, credentials='azure-se', is_default=True, is_public=True, extra={'api_base': 'https://opperopenaiservice.openai.azure.com', 'api_version': '2023-05-15', 'dimensions': 1536})` will be used"""


class CreateEmbeddingRequest(BaseModel):
    input: Input
    r"""The input to embed, can be a single string or a list of strings"""

    model: OptionalNullable[TModel] = UNSET
    r"""The model to use for the embedding, if not provided, `EmbeddingModel(hosting_provider='Azure', location='EU', identifier='azure/text-embedding-3-large', name='azure/text-embedding-3-large-1536', dimensions=1536, max_tokens=8191, credentials='azure-se', is_default=True, is_public=True, extra={'api_base': 'https://opperopenaiservice.openai.azure.com', 'api_version': '2023-05-15', 'dimensions': 1536})` will be used"""

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