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

from __future__ import annotations
from .classifierfinetuningjob import (
    ClassifierFineTuningJob,
    ClassifierFineTuningJobTypedDict,
)
from .completionfinetuningjob import (
    CompletionFineTuningJob,
    CompletionFineTuningJobTypedDict,
)
from functools import partial
from mistralai.client.types import BaseModel, UNSET_SENTINEL
from mistralai.client.utils import validate_const
from mistralai.client.utils.unions import parse_open_union
import pydantic
from pydantic import ConfigDict, model_serializer
from pydantic.functional_validators import AfterValidator, BeforeValidator
from typing import Any, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


ListFineTuningJobsResponseDataTypedDict = TypeAliasType(
    "ListFineTuningJobsResponseDataTypedDict",
    Union[ClassifierFineTuningJobTypedDict, CompletionFineTuningJobTypedDict],
)


class UnknownListFineTuningJobsResponseData(BaseModel):
    r"""A ListFineTuningJobsResponseData variant the SDK doesn't recognize. Preserves the raw payload."""

    job_type: Literal["UNKNOWN"] = "UNKNOWN"
    raw: Any
    is_unknown: Literal[True] = True

    model_config = ConfigDict(frozen=True)


_LIST_FINE_TUNING_JOBS_RESPONSE_DATA_VARIANTS: dict[str, Any] = {
    "classifier": ClassifierFineTuningJob,
    "completion": CompletionFineTuningJob,
}


ListFineTuningJobsResponseData = Annotated[
    Union[
        ClassifierFineTuningJob,
        CompletionFineTuningJob,
        UnknownListFineTuningJobsResponseData,
    ],
    BeforeValidator(
        partial(
            parse_open_union,
            disc_key="job_type",
            variants=_LIST_FINE_TUNING_JOBS_RESPONSE_DATA_VARIANTS,
            unknown_cls=UnknownListFineTuningJobsResponseData,
            union_name="ListFineTuningJobsResponseData",
        )
    ),
]


class ListFineTuningJobsResponseTypedDict(TypedDict):
    total: int
    data: NotRequired[List[ListFineTuningJobsResponseDataTypedDict]]
    object: Literal["list"]


class ListFineTuningJobsResponse(BaseModel):
    total: int

    data: Optional[List[ListFineTuningJobsResponseData]] = None

    object: Annotated[
        Annotated[Optional[Literal["list"]], AfterValidator(validate_const("list"))],
        pydantic.Field(alias="object"),
    ] = "list"

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

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m


try:
    ListFineTuningJobsResponse.model_rebuild()
except NameError:
    pass
