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

from __future__ import annotations
from .batcherror import BatchError, BatchErrorTypedDict
from .batchjobstatus import BatchJobStatus
from mistralai.client.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
)
from mistralai.client.utils import validate_const
import pydantic
from pydantic import model_serializer
from pydantic.functional_validators import AfterValidator
from typing import Any, Dict, List, Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class BatchJobTypedDict(TypedDict):
    id: str
    input_files: List[str]
    endpoint: str
    errors: List[BatchErrorTypedDict]
    status: BatchJobStatus
    created_at: int
    total_requests: int
    completed_requests: int
    succeeded_requests: int
    failed_requests: int
    object: Literal["batch"]
    metadata: NotRequired[Nullable[Dict[str, Any]]]
    model: NotRequired[Nullable[str]]
    agent_id: NotRequired[Nullable[str]]
    output_file: NotRequired[Nullable[str]]
    error_file: NotRequired[Nullable[str]]
    outputs: NotRequired[Nullable[List[Dict[str, Any]]]]
    started_at: NotRequired[Nullable[int]]
    completed_at: NotRequired[Nullable[int]]


class BatchJob(BaseModel):
    id: str

    input_files: List[str]

    endpoint: str

    errors: List[BatchError]

    status: BatchJobStatus

    created_at: int

    total_requests: int

    completed_requests: int

    succeeded_requests: int

    failed_requests: int

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

    metadata: OptionalNullable[Dict[str, Any]] = UNSET

    model: OptionalNullable[str] = UNSET

    agent_id: OptionalNullable[str] = UNSET

    output_file: OptionalNullable[str] = UNSET

    error_file: OptionalNullable[str] = UNSET

    outputs: OptionalNullable[List[Dict[str, Any]]] = UNSET

    started_at: OptionalNullable[int] = UNSET

    completed_at: OptionalNullable[int] = UNSET

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "object",
                "metadata",
                "model",
                "agent_id",
                "output_file",
                "error_file",
                "outputs",
                "started_at",
                "completed_at",
            ]
        )
        nullable_fields = set(
            [
                "metadata",
                "model",
                "agent_id",
                "output_file",
                "error_file",
                "outputs",
                "started_at",
                "completed_at",
            ]
        )
        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:
    BatchJob.model_rebuild()
except NameError:
    pass
