# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Dict, List, Union, Optional
from datetime import datetime
from typing_extensions import Literal, TypeAlias

from pydantic import Field as FieldInfo

from ...._models import BaseModel
from ...parsing_mode import ParsingMode
from ...fail_page_mode import FailPageMode
from ...parsing_languages import ParsingLanguages
from ...classifier.classify_job import ClassifyJob
from ...extraction.webhook_configuration import WebhookConfiguration

__all__ = [
    "JobItemGetProcessingResultsResponse",
    "ProcessingResult",
    "ProcessingResultJobConfig",
    "ProcessingResultJobConfigBatchParseJobRecordCreate",
    "ProcessingResultJobConfigBatchParseJobRecordCreateParameters",
]


class ProcessingResultJobConfigBatchParseJobRecordCreateParameters(BaseModel):
    """Generic parse job configuration for batch processing.

    This model contains the parsing configuration that applies to all files
    in a batch, but excludes file-specific fields like file_name, file_id, etc.
    Those file-specific fields are populated from DirectoryFile data when
    creating individual ParseJobRecordCreate instances for each file.

    The fields in this model should be generic settings that apply uniformly
    to all files being processed in the batch.
    """

    adaptive_long_table: Optional[bool] = None

    aggressive_table_extraction: Optional[bool] = None

    annotate_links: Optional[bool] = None

    auto_mode: Optional[bool] = None

    auto_mode_configuration_json: Optional[str] = None

    auto_mode_trigger_on_image_in_page: Optional[bool] = None

    auto_mode_trigger_on_regexp_in_page: Optional[str] = None

    auto_mode_trigger_on_table_in_page: Optional[bool] = None

    auto_mode_trigger_on_text_in_page: Optional[str] = None

    azure_openai_api_version: Optional[str] = None

    azure_openai_deployment_name: Optional[str] = None

    azure_openai_endpoint: Optional[str] = None

    azure_openai_key: Optional[str] = None

    bbox_bottom: Optional[float] = None

    bbox_left: Optional[float] = None

    bbox_right: Optional[float] = None

    bbox_top: Optional[float] = None

    bounding_box: Optional[str] = None

    compact_markdown_table: Optional[bool] = None

    complemental_formatting_instruction: Optional[str] = None

    content_guideline_instruction: Optional[str] = None

    continuous_mode: Optional[bool] = None

    custom_metadata: Optional[Dict[str, object]] = None
    """The custom metadata to attach to the documents."""

    disable_image_extraction: Optional[bool] = None

    disable_ocr: Optional[bool] = None

    disable_reconstruction: Optional[bool] = None

    do_not_cache: Optional[bool] = None

    do_not_unroll_columns: Optional[bool] = None

    extract_charts: Optional[bool] = None

    extract_layout: Optional[bool] = None

    extract_printed_page_number: Optional[bool] = None

    fast_mode: Optional[bool] = None

    formatting_instruction: Optional[str] = None

    gpt4o_api_key: Optional[str] = None

    gpt4o_mode: Optional[bool] = None

    guess_xlsx_sheet_name: Optional[bool] = None

    hide_footers: Optional[bool] = None

    hide_headers: Optional[bool] = None

    high_res_ocr: Optional[bool] = None

    html_make_all_elements_visible: Optional[bool] = None

    html_remove_fixed_elements: Optional[bool] = None

    html_remove_navigation_elements: Optional[bool] = None

    http_proxy: Optional[str] = None

    ignore_document_elements_for_layout_detection: Optional[bool] = None

    images_to_save: Optional[List[Literal["screenshot", "embedded", "layout"]]] = None

    inline_images_in_markdown: Optional[bool] = None

    input_s3_path: Optional[str] = None

    input_s3_region: Optional[str] = None
    """The region for the input S3 bucket."""

    input_url: Optional[str] = None

    internal_is_screenshot_job: Optional[bool] = None

    invalidate_cache: Optional[bool] = None

    is_formatting_instruction: Optional[bool] = None

    job_timeout_extra_time_per_page_in_seconds: Optional[float] = None

    job_timeout_in_seconds: Optional[float] = None

    keep_page_separator_when_merging_tables: Optional[bool] = None

    lang: Optional[str] = None
    """The language."""

    languages: Optional[List[ParsingLanguages]] = None

    layout_aware: Optional[bool] = None

    line_level_bounding_box: Optional[bool] = None

    markdown_table_multiline_header_separator: Optional[str] = None

    max_pages: Optional[int] = None

    max_pages_enforced: Optional[int] = None

    merge_tables_across_pages_in_markdown: Optional[bool] = None

    model: Optional[str] = None

    outlined_table_extraction: Optional[bool] = None

    output_pdf_of_document: Optional[bool] = None

    output_s3_path_prefix: Optional[str] = None
    """If specified, llamaParse will save the output to the specified path.

    All output file will use this 'prefix' should be a valid s3:// url
    """

    output_s3_region: Optional[str] = None
    """The region for the output S3 bucket."""

    output_tables_as_html: Optional[bool] = FieldInfo(alias="output_tables_as_HTML", default=None)

    output_bucket: Optional[str] = FieldInfo(alias="outputBucket", default=None)
    """The output bucket."""

    page_error_tolerance: Optional[float] = None

    page_footer_prefix: Optional[str] = None

    page_footer_suffix: Optional[str] = None

    page_header_prefix: Optional[str] = None

    page_header_suffix: Optional[str] = None

    page_prefix: Optional[str] = None

    page_separator: Optional[str] = None

    page_suffix: Optional[str] = None

    parse_mode: Optional[ParsingMode] = None
    """Enum for representing the mode of parsing to be used."""

    parsing_instruction: Optional[str] = None

    pipeline_id: Optional[str] = None
    """The pipeline ID."""

    precise_bounding_box: Optional[bool] = None

    premium_mode: Optional[bool] = None

    presentation_out_of_bounds_content: Optional[bool] = None

    presentation_skip_embedded_data: Optional[bool] = None

    preserve_layout_alignment_across_pages: Optional[bool] = None

    preserve_very_small_text: Optional[bool] = None

    preset: Optional[str] = None

    priority: Optional[Literal["low", "medium", "high", "critical"]] = None
    """The priority for the request.

    This field may be ignored or overwritten depending on the organization tier.
    """

    project_id: Optional[str] = None

    remove_hidden_text: Optional[bool] = None

    replace_failed_page_mode: Optional[FailPageMode] = None
    """Enum for representing the different available page error handling modes."""

    replace_failed_page_with_error_message_prefix: Optional[str] = None

    replace_failed_page_with_error_message_suffix: Optional[str] = None

    resource_info: Optional[Dict[str, object]] = None
    """The resource info about the file"""

    save_images: Optional[bool] = None

    skip_diagonal_text: Optional[bool] = None

    specialized_chart_parsing_agentic: Optional[bool] = None

    specialized_chart_parsing_efficient: Optional[bool] = None

    specialized_chart_parsing_plus: Optional[bool] = None

    specialized_image_parsing: Optional[bool] = None

    spreadsheet_extract_sub_tables: Optional[bool] = None

    spreadsheet_force_formula_computation: Optional[bool] = None

    strict_mode_buggy_font: Optional[bool] = None

    strict_mode_image_extraction: Optional[bool] = None

    strict_mode_image_ocr: Optional[bool] = None

    strict_mode_reconstruction: Optional[bool] = None

    structured_output: Optional[bool] = None

    structured_output_json_schema: Optional[str] = None

    structured_output_json_schema_name: Optional[str] = None

    system_prompt: Optional[str] = None

    system_prompt_append: Optional[str] = None

    take_screenshot: Optional[bool] = None

    target_pages: Optional[str] = None

    tier: Optional[str] = None

    type: Optional[Literal["parse"]] = None

    use_vendor_multimodal_model: Optional[bool] = None

    user_prompt: Optional[str] = None

    vendor_multimodal_api_key: Optional[str] = None

    vendor_multimodal_model_name: Optional[str] = None

    version: Optional[str] = None

    webhook_configurations: Optional[List[WebhookConfiguration]] = None
    """The outbound webhook configurations"""

    webhook_url: Optional[str] = None


class ProcessingResultJobConfigBatchParseJobRecordCreate(BaseModel):
    """Batch-specific parse job record for batch processing.

    This model contains the metadata and configuration for a batch parse job,
    but excludes file-specific information. It's used as input to the batch
    parent workflow and combined with DirectoryFile data to create full
    ParseJobRecordCreate instances for each file.

    Attributes:
        job_name: Must be PARSE_RAW_FILE
        partitions: Partitions for job output location
        parameters: Generic parse configuration (BatchParseJobConfig)
        session_id: Upstream request ID for tracking
        correlation_id: Correlation ID for cross-service tracking
        parent_job_execution_id: Parent job execution ID if nested
        user_id: User who created the job
        project_id: Project this job belongs to
        webhook_url: Optional webhook URL for job completion notifications
    """

    correlation_id: Optional[str] = None
    """The correlation ID for this job. Used for tracking the job across services."""

    job_name: Optional[Literal["parse_raw_file_job"]] = None

    parameters: Optional[ProcessingResultJobConfigBatchParseJobRecordCreateParameters] = None
    """Generic parse job configuration for batch processing.

    This model contains the parsing configuration that applies to all files in a
    batch, but excludes file-specific fields like file_name, file_id, etc. Those
    file-specific fields are populated from DirectoryFile data when creating
    individual ParseJobRecordCreate instances for each file.

    The fields in this model should be generic settings that apply uniformly to all
    files being processed in the batch.
    """

    parent_job_execution_id: Optional[str] = None
    """The ID of the parent job execution."""

    partitions: Optional[Dict[str, str]] = None
    """The partitions for this execution.

    Used for determining where to save job output.
    """

    project_id: Optional[str] = None
    """The ID of the project this job belongs to."""

    session_id: Optional[str] = None
    """The upstream request ID that created this job.

    Used for tracking the job across services.
    """

    user_id: Optional[str] = None
    """The ID of the user that created this job"""

    webhook_url: Optional[str] = None
    """The URL that needs to be called at the end of the parsing job."""


ProcessingResultJobConfig: TypeAlias = Union[ProcessingResultJobConfigBatchParseJobRecordCreate, ClassifyJob]


class ProcessingResult(BaseModel):
    """A processing result with lineage information."""

    item_id: str
    """Source item that was processed"""

    job_config: ProcessingResultJobConfig
    """Job configuration used for processing"""

    job_type: Literal["parse", "extract", "classify"]
    """Type of processing performed"""

    output_s3_path: str
    """S3 location of processing output"""

    parameters_hash: str
    """Hash of parameters for deduplication"""

    processed_at: datetime
    """When this processing occurred"""

    result_id: str
    """Unique identifier for this result"""

    output_metadata: Optional[object] = None
    """Metadata about processing output.

    Currently empty - will be populated with job-type-specific metadata fields in
    the future.
    """


class JobItemGetProcessingResultsResponse(BaseModel):
    """Response containing all processing results for an item."""

    item_id: str
    """ID of the source item"""

    item_name: str
    """Name of the source item"""

    processing_results: Optional[List[ProcessingResult]] = None
    """List of all processing operations performed on this item"""
