# This file was auto-generated by Fern from our API Definition.

from ..core.pydantic_utilities import UniversalBaseModel
from .job_names import JobNames
import pydantic
import typing
from .base import Base
import datetime as dt
from .status_enum import StatusEnum
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class JobRecord(UniversalBaseModel):
    """
    Schema for a job's metadata.
    """

    job_name: JobNames = pydantic.Field()
    """
    The name of the job.
    """

    partitions: typing.Dict[str, str] = pydantic.Field()
    """
    The partitions for this execution. Used for determining where to save job output.
    """

    parameters: typing.Optional[Base] = pydantic.Field(default=None)
    """
    Additional metadata for the job execution.
    """

    session_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The upstream request ID that created this job. Used for tracking the job across services.
    """

    correlation_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The correlation ID for this job. Used for tracking the job across services.
    """

    parent_job_execution_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The ID of the parent job execution.
    """

    user_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The ID of the user that created this job
    """

    created_at: dt.datetime = pydantic.Field()
    """
    Creation datetime
    """

    project_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The ID of the project this job belongs to.
    """

    priority: typing.Optional[int] = pydantic.Field(default=None)
    """
    The priority of the job message in the queue from 1-5, None being no priority just FIFO
    """

    id: typing.Optional[str] = pydantic.Field(default=None)
    """
    Unique identifier
    """

    status: StatusEnum
    error_code: typing.Optional[str] = None
    error_message: typing.Optional[str] = None
    attempts: typing.Optional[int] = pydantic.Field(default=None)
    """
    The number of times this job has been attempted
    """

    started_at: typing.Optional[dt.datetime] = None
    ended_at: typing.Optional[dt.datetime] = None
    updated_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Update datetime
    """

    data: typing.Optional[Base] = pydantic.Field(default=None)
    """
    Additional metadata for the job execution.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
