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

from __future__ import annotations
from .checkpoint import Checkpoint, CheckpointTypedDict
from .completiontrainingparameters import (
    CompletionTrainingParameters,
    CompletionTrainingParametersTypedDict,
)
from .event import Event, EventTypedDict
from .githubrepository import GithubRepository, GithubRepositoryTypedDict
from .jobmetadata import JobMetadata, JobMetadataTypedDict
from .wandbintegrationresult import (
    WandbIntegrationResult,
    WandbIntegrationResultTypedDict,
)
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from mistralai.client.utils import validate_const
import pydantic
from pydantic import ConfigDict, model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Any, List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


CompletionFineTuningJobDetailsStatus = Union[
    Literal[
        "QUEUED",
        "STARTED",
        "VALIDATING",
        "VALIDATED",
        "RUNNING",
        "FAILED_VALIDATION",
        "FAILED",
        "SUCCESS",
        "CANCELLED",
        "CANCELLATION_REQUESTED",
    ],
    UnrecognizedStr,
]


CompletionFineTuningJobDetailsIntegrationTypedDict = WandbIntegrationResultTypedDict


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

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

    model_config = ConfigDict(frozen=True)


_COMPLETION_FINE_TUNING_JOB_DETAILS_INTEGRATION_VARIANTS: dict[str, Any] = {
    "wandb": WandbIntegrationResult,
}


CompletionFineTuningJobDetailsIntegration = WandbIntegrationResult


CompletionFineTuningJobDetailsRepositoryTypedDict = GithubRepositoryTypedDict


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

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

    model_config = ConfigDict(frozen=True)


_COMPLETION_FINE_TUNING_JOB_DETAILS_REPOSITORY_VARIANTS: dict[str, Any] = {
    "github": GithubRepository,
}


CompletionFineTuningJobDetailsRepository = GithubRepository


class CompletionFineTuningJobDetailsTypedDict(TypedDict):
    id: str
    auto_start: bool
    model: str
    status: CompletionFineTuningJobDetailsStatus
    created_at: int
    modified_at: int
    training_files: List[str]
    hyperparameters: CompletionTrainingParametersTypedDict
    validation_files: NotRequired[Nullable[List[str]]]
    object: Literal["job"]
    fine_tuned_model: NotRequired[Nullable[str]]
    suffix: NotRequired[Nullable[str]]
    integrations: NotRequired[
        Nullable[List[CompletionFineTuningJobDetailsIntegrationTypedDict]]
    ]
    trained_tokens: NotRequired[Nullable[int]]
    metadata: NotRequired[Nullable[JobMetadataTypedDict]]
    job_type: Literal["completion"]
    repositories: NotRequired[List[CompletionFineTuningJobDetailsRepositoryTypedDict]]
    events: NotRequired[List[EventTypedDict]]
    r"""Event items are created every time the status of a fine-tuning job changes. The timestamped list of all events is accessible here."""
    checkpoints: NotRequired[List[CheckpointTypedDict]]


class CompletionFineTuningJobDetails(BaseModel):
    id: str

    auto_start: bool

    model: str

    status: CompletionFineTuningJobDetailsStatus

    created_at: int

    modified_at: int

    training_files: List[str]

    hyperparameters: CompletionTrainingParameters

    validation_files: OptionalNullable[List[str]] = UNSET

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

    fine_tuned_model: OptionalNullable[str] = UNSET

    suffix: OptionalNullable[str] = UNSET

    integrations: OptionalNullable[List[CompletionFineTuningJobDetailsIntegration]] = (
        UNSET
    )

    trained_tokens: OptionalNullable[int] = UNSET

    metadata: OptionalNullable[JobMetadata] = UNSET

    job_type: Annotated[
        Annotated[Literal["completion"], AfterValidator(validate_const("completion"))],
        pydantic.Field(alias="job_type"),
    ] = "completion"

    repositories: Optional[List[CompletionFineTuningJobDetailsRepository]] = None

    events: Optional[List[Event]] = None
    r"""Event items are created every time the status of a fine-tuning job changes. The timestamped list of all events is accessible here."""

    checkpoints: Optional[List[Checkpoint]] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "validation_files",
                "object",
                "fine_tuned_model",
                "suffix",
                "integrations",
                "trained_tokens",
                "metadata",
                "repositories",
                "events",
                "checkpoints",
            ]
        )
        nullable_fields = set(
            [
                "validation_files",
                "fine_tuned_model",
                "suffix",
                "integrations",
                "trained_tokens",
                "metadata",
            ]
        )
        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:
    CompletionFineTuningJobDetails.model_rebuild()
except NameError:
    pass
