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

from __future__ import annotations
from .file import File, FileTypedDict
from .timestampgranularity import TimestampGranularity
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import FieldMetadata, MultipartFormMetadata, validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class AudioTranscriptionRequestTypedDict(TypedDict):
    model: str
    r"""ID of the model to be used."""
    file: NotRequired[FileTypedDict]
    file_url: NotRequired[Nullable[str]]
    r"""Url of a file to be transcribed"""
    file_id: NotRequired[Nullable[str]]
    r"""ID of a file uploaded to /v1/files"""
    language: NotRequired[Nullable[str]]
    r"""Language of the audio, e.g. 'en'. Providing the language can boost accuracy."""
    temperature: NotRequired[Nullable[float]]
    stream: Literal[False]
    diarize: NotRequired[bool]
    context_bias: NotRequired[List[str]]
    timestamp_granularities: NotRequired[List[TimestampGranularity]]
    r"""Granularities of timestamps to include in the response."""


class AudioTranscriptionRequest(BaseModel):
    model: Annotated[str, FieldMetadata(multipart=True)]
    r"""ID of the model to be used."""

    file: Annotated[
        Optional[File], FieldMetadata(multipart=MultipartFormMetadata(file=True))
    ] = None

    file_url: Annotated[OptionalNullable[str], FieldMetadata(multipart=True)] = UNSET
    r"""Url of a file to be transcribed"""

    file_id: Annotated[OptionalNullable[str], FieldMetadata(multipart=True)] = UNSET
    r"""ID of a file uploaded to /v1/files"""

    language: Annotated[OptionalNullable[str], FieldMetadata(multipart=True)] = UNSET
    r"""Language of the audio, e.g. 'en'. Providing the language can boost accuracy."""

    temperature: Annotated[OptionalNullable[float], FieldMetadata(multipart=True)] = (
        UNSET
    )

    stream: Annotated[
        Annotated[Optional[Literal[False]], AfterValidator(validate_const(False))],
        pydantic.Field(alias="stream"),
        FieldMetadata(multipart=True),
    ] = False

    diarize: Annotated[Optional[bool], FieldMetadata(multipart=True)] = False

    context_bias: Annotated[Optional[List[str]], FieldMetadata(multipart=True)] = None

    timestamp_granularities: Annotated[
        Optional[List[TimestampGranularity]], FieldMetadata(multipart=True)
    ] = None
    r"""Granularities of timestamps to include in the response."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "file",
                "file_url",
                "file_id",
                "language",
                "temperature",
                "stream",
                "diarize",
                "context_bias",
                "timestamp_granularities",
            ]
        )
        nullable_fields = set(["file_url", "file_id", "language", "temperature"])
        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:
    AudioTranscriptionRequest.model_rebuild()
except NameError:
    pass
