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

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.serialization import FieldMetadata
from ..core.unchecked_base_model import UncheckedBaseModel
from .classifier_summary import ClassifierSummary
from .classifier_version_summary import ClassifierVersionSummary
from .classify_config import ClassifyConfig
from .classify_output import ClassifyOutput
from .created_at import CreatedAt
from .file_summary import FileSummary
from .processor_run_status import ProcessorRunStatus
from .run_metadata import RunMetadata
from .run_usage import RunUsage
from .updated_at import UpdatedAt


class ClassifyRun(UncheckedBaseModel):
    """
    Classify run object.
    """

    object: typing.Literal["classify_run"] = pydantic.Field(default="classify_run")
    """
    The type of object. Will always be `"classify_run"`.
    """

    id: str = pydantic.Field()
    """
    The unique identifier for this classify run.
    
    Example: `"clr_Xj8mK2pL9nR4vT7qY5wZ"`
    """

    classifier: typing.Optional[ClassifierSummary] = pydantic.Field(default=None)
    """
    The classifier that was used for this run.
    
    **Availability:** Present when a classifier reference was provided. Not present when using inline `config`.
    """

    classifier_version: typing_extensions.Annotated[
        typing.Optional[ClassifierVersionSummary], FieldMetadata(alias="classifierVersion")
    ] = pydantic.Field(alias="classifierVersion", default=None)
    """
    The version of the classifier that was used for this run.
    
    **Availability:** Present when a classifier reference was provided. Not present when using inline `config`.
    """

    status: ProcessorRunStatus
    output: typing.Optional[ClassifyOutput] = pydantic.Field(default=None)
    """
    The final output, either reviewed or initial.
    
    **Availability:** Present when `status` is `"PROCESSED"`.
    """

    initial_output: typing_extensions.Annotated[
        typing.Optional[ClassifyOutput], FieldMetadata(alias="initialOutput")
    ] = pydantic.Field(alias="initialOutput", default=None)
    """
    The initial output from the classify run, before any review edits.
    
    **Availability:** Present when `reviewed` is `true`.
    """

    reviewed_output: typing_extensions.Annotated[
        typing.Optional[ClassifyOutput], FieldMetadata(alias="reviewedOutput")
    ] = pydantic.Field(alias="reviewedOutput", default=None)
    """
    The output after human review.
    
    **Availability:** Present when `reviewed` is `true`.
    """

    failure_reason: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="failureReason")] = (
        pydantic.Field(alias="failureReason", default=None)
    )
    """
    The reason for failure.
    
    **Availability:** Present when `status` is `"FAILED"`.
    
    Possible values include:
    * `ABORTED` - The run was aborted by the user
    * `INTERNAL_ERROR` - An unexpected internal error occurred
    * `FAILED_TO_PROCESS_FILE` - Failed to process the file (e.g., OCR failure, file access issues)
    * `INVALID_PROCESSOR` - The processor configuration is invalid
    * `INVALID_CONFIGURATION` - The provided configuration is incompatible with the selected model
    * `PARSING_ERROR` - Failed to parse the classification output
    * `PRE_PROCESSING_FAILURE` - An error occurred during preprocessing
    * `POST_PROCESSING_FAILURE` - An error occurred during postprocessing
    * `OUT_OF_CREDITS` - Insufficient credits to run the classification
    
    **Note:** Additional failure reasons may be added in the future. Your integration should handle unknown values gracefully.
    """

    failure_message: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="failureMessage")] = (
        pydantic.Field(alias="failureMessage", default=None)
    )
    """
    A detailed message about the failure.
    
    **Availability:** Present when `status` is `"FAILED"`.
    """

    metadata: typing.Optional[RunMetadata] = pydantic.Field(default=None)
    """
    Any metadata that was provided when creating the classify run.
    
    **Availability:** Present when metadata was provided during creation.
    """

    reviewed: bool = pydantic.Field()
    """
    Indicates whether the run has been reviewed by a human.
    """

    edited: bool = pydantic.Field()
    """
    Indicates whether the run results have been edited during review.
    """

    config: ClassifyConfig = pydantic.Field()
    """
    The configuration used for this classify run.
    """

    file: FileSummary = pydantic.Field()
    """
    The file that was processed.
    """

    parse_run_id: typing_extensions.Annotated[typing.Optional[str], FieldMetadata(alias="parseRunId")] = pydantic.Field(
        alias="parseRunId", default=None
    )
    """
    The ID of the parse run that was used for this classify run.
    
    **Availability:** Present when a parse run was created.
    """

    dashboard_url: typing_extensions.Annotated[str, FieldMetadata(alias="dashboardUrl")] = pydantic.Field(
        alias="dashboardUrl"
    )
    """
    The URL to view the classify run in the Extend dashboard.
    """

    usage: typing.Optional[RunUsage] = pydantic.Field(default=None)
    """
    Usage credits consumed by this run.
    
    **Availability:** This field will not be returned for:
    * Runs created before October 7, 2025
    * Customers on legacy billing systems
    """

    created_at: typing_extensions.Annotated[CreatedAt, FieldMetadata(alias="createdAt")] = pydantic.Field(
        alias="createdAt"
    )
    updated_at: typing_extensions.Annotated[UpdatedAt, FieldMetadata(alias="updatedAt")] = pydantic.Field(
        alias="updatedAt"
    )

    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
