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

from ..core.pydantic_utilities import UniversalBaseModel
import pydantic
import typing
import datetime as dt
from .extract_run_data_schema_value import ExtractRunDataSchemaValue
from .extract_config import ExtractConfig
from .file import File
from .extract_state import ExtractState
from .data import Data
from .extract_run_extraction_metadata_value import ExtractRunExtractionMetadataValue
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class ExtractRun(UniversalBaseModel):
    """
    Schema for an extraction run.
    """

    id: str = pydantic.Field()
    """
    The id of the extraction run
    """

    created_at: typing.Optional[dt.datetime] = pydantic.Field(default=None)
    """
    Creation datetime
    """

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

    extraction_agent_id: str = pydantic.Field()
    """
    The id of the extraction agent
    """

    data_schema: typing.Dict[str, typing.Optional[ExtractRunDataSchemaValue]] = pydantic.Field()
    """
    The schema used for extraction
    """

    config: ExtractConfig = pydantic.Field()
    """
    The config used for extraction
    """

    file: File = pydantic.Field()
    """
    The file that the extract was extracted from
    """

    status: ExtractState = pydantic.Field()
    """
    The status of the extraction run
    """

    error: typing.Optional[str] = pydantic.Field(default=None)
    """
    The error that occurred during extraction
    """

    job_id: typing.Optional[str] = pydantic.Field(default=None)
    """
    The id of the job that the extraction run belongs to
    """

    data: typing.Optional[Data] = pydantic.Field(default=None)
    """
    The data extracted from the file
    """

    extraction_metadata: typing.Optional[typing.Dict[str, typing.Optional[ExtractRunExtractionMetadataValue]]] = (
        pydantic.Field(default=None)
    )
    """
    The metadata extracted from the file
    """

    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
