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

from __future__ import annotations

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2, update_forward_refs
from ..core.serialization import FieldMetadata
from ..core.unchecked_base_model import UncheckedBaseModel
from .edit_config import EditConfig
from .edit_run_metrics import EditRunMetrics
from .edit_run_output import EditRunOutput
from .edit_run_status import EditRunStatus
from .file_summary import FileSummary
from .run_usage import RunUsage


class EditRun(UncheckedBaseModel):
    """
    Edit run object.
    """

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

    id: str = pydantic.Field()
    """
    A unique identifier for the edit run.
    
    Example: `"edr_xK9mLPqRtN3vS8wF5hB2cQ"`
    """

    file: FileSummary = pydantic.Field()
    """
    The input file that was submitted for editing.
    """

    status: EditRunStatus = pydantic.Field()
    """
    The status of the edit run:
    * `"PROCESSING"` - The file is still being processed
    * `"PROCESSED"` - The file was successfully edited
    * `"FAILED"` - The editing failed (see `failureReason` for details)
    """

    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:
    * `UNABLE_TO_DOWNLOAD_FILE` - Failed to load the requested file
    * `FILE_TYPE_NOT_SUPPORTED` - File type not supported. Edit runs currently require a PDF
    * `FILE_SIZE_TOO_LARGE` - The file exceeds the maximum allowed size
    * `CORRUPT_FILE` - The file appears to be corrupted and cannot be edited
    * `FIELD_DETECTION_ERROR` - An error occurred during field detection
    * `PASSWORD_PROTECTED_FILE` - The file is password protected and cannot be edited
    * `FAILED_TO_CONVERT_TO_PDF` - The file could not be converted to PDF for processing
    * `INTERNAL_ERROR` - An unexpected internal error occurred
    * `INVALID_OPTIONS` - The provided configuration options are invalid
    * `EMPTY_SCHEMA` - No schema was provided and no fields could be detected
    * `OUT_OF_CREDITS` - Insufficient credits to process the file
    
    **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 human-readable description of the failure.
    
    **Availability:** Present when `status` is `"FAILED"`.
    """

    config: EditConfig = pydantic.Field()
    """
    The configuration used for this edit run, including any default values that were applied.
    """

    output: typing.Optional[EditRunOutput] = pydantic.Field(default=None)
    """
    The output of the edit run.
    
    **Availability:** Present when `status` is `"PROCESSED"`.
    """

    metrics: typing.Optional[EditRunMetrics] = pydantic.Field(default=None)
    """
    Metrics about the editing process.
    
    **Availability:** Present when `status` is `"PROCESSED"`.
    """

    usage: typing.Optional[RunUsage] = pydantic.Field(default=None)
    """
    Usage credits consumed by this run.
    
    **Availability:** Present when `status` is `"PROCESSED"`, the run was created after October 7, 2025, and the customer is on the current billing system.
    """

    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


update_forward_refs(EditRun)
