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

from __future__ import annotations
from .jobin import JobIn, JobInTypedDict
from .jobout import JobOut, JobOutTypedDict
from .legacyjobmetadataout import LegacyJobMetadataOut, LegacyJobMetadataOutTypedDict
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
from mistralai.utils import FieldMetadata, QueryParamMetadata, RequestMetadata
from pydantic import model_serializer
from typing import TypedDict, Union
from typing_extensions import Annotated, NotRequired


class JobsAPIRoutesFineTuningCreateFineTuningJobRequestTypedDict(TypedDict):
    job_in: JobInTypedDict
    dry_run: NotRequired[Nullable[bool]]
    r"""* If `true` the job is not spawned, instead the query returns a handful of useful metadata
    for the user to perform sanity checks (see `LegacyJobMetadataOut` response).
    * Otherwise, the job is started and the query returns the job ID along with some of the
    input parameters (see `JobOut` response).

    """
    

class JobsAPIRoutesFineTuningCreateFineTuningJobRequest(BaseModel):
    job_in: Annotated[JobIn, FieldMetadata(request=RequestMetadata(media_type="application/json"))]
    dry_run: Annotated[OptionalNullable[bool], FieldMetadata(query=QueryParamMetadata(style="form", explode=True))] = UNSET
    r"""* If `true` the job is not spawned, instead the query returns a handful of useful metadata
    for the user to perform sanity checks (see `LegacyJobMetadataOut` response).
    * Otherwise, the job is started and the query returns the job ID along with some of the
    input parameters (see `JobOut` response).

    """
    
    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = ["dry_run"]
        nullable_fields = ["dry_run"]
        null_default_fields = []

        serialized = handler(self)

        m = {}

        for n, f in self.model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            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
        

JobsAPIRoutesFineTuningCreateFineTuningJobResponseTypedDict = Union[LegacyJobMetadataOutTypedDict, JobOutTypedDict]
r"""OK"""


JobsAPIRoutesFineTuningCreateFineTuningJobResponse = Union[LegacyJobMetadataOut, JobOut]
r"""OK"""

