/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 0154047eeec4
 */

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { ClosedEnum } from "../../types/enums.js";
import { smartUnion } from "../../types/smartUnion.js";
import {
  DocumentURLChunk,
  DocumentURLChunk$Outbound,
  DocumentURLChunk$outboundSchema,
} from "./documenturlchunk.js";
import {
  FileChunk,
  FileChunk$Outbound,
  FileChunk$outboundSchema,
} from "./filechunk.js";
import {
  ImageURLChunk,
  ImageURLChunk$Outbound,
  ImageURLChunk$outboundSchema,
} from "./imageurlchunk.js";
import {
  ResponseFormat,
  ResponseFormat$Outbound,
  ResponseFormat$outboundSchema,
} from "./responseformat.js";

/**
 * Document to run OCR on
 */
export type DocumentUnion = FileChunk | DocumentURLChunk | ImageURLChunk;

/**
 * Specific pages to process. Accepts a list of integers or a string of comma-separated numbers and ranges (e.g. '0,1,2' or '0-5' or '0,2-4'). Page numbers start from 0.
 */
export type Pages = string | Array<number>;

export const TableFormat = {
  Markdown: "markdown",
  Html: "html",
} as const;
export type TableFormat = ClosedEnum<typeof TableFormat>;

export const ConfidenceScoresGranularity = {
  Word: "word",
  Page: "page",
} as const;
export type ConfidenceScoresGranularity = ClosedEnum<
  typeof ConfidenceScoresGranularity
>;

export type OCRRequest = {
  model: string | null;
  id?: string | undefined;
  /**
   * Document to run OCR on
   */
  document: FileChunk | DocumentURLChunk | ImageURLChunk;
  /**
   * Specific pages to process. Accepts a list of integers or a string of comma-separated numbers and ranges (e.g. '0,1,2' or '0-5' or '0,2-4'). Page numbers start from 0.
   */
  pages?: string | Array<number> | null | undefined;
  /**
   * Include image URLs in response
   */
  includeImageBase64?: boolean | null | undefined;
  /**
   * Max images to extract
   */
  imageLimit?: number | null | undefined;
  /**
   * Minimum height and width of image to extract
   */
  imageMinSize?: number | null | undefined;
  /**
   * Structured output class for extracting useful information from each extracted bounding box / image from document. Only json_schema is valid for this field
   */
  bboxAnnotationFormat?: ResponseFormat | null | undefined;
  /**
   * Structured output class for extracting useful information from the entire document. Only json_schema is valid for this field
   */
  documentAnnotationFormat?: ResponseFormat | null | undefined;
  /**
   * Optional prompt to guide the model in extracting structured output from the entire document. A document_annotation_format must be provided.
   */
  documentAnnotationPrompt?: string | null | undefined;
  tableFormat?: TableFormat | null | undefined;
  extractHeader?: boolean | undefined;
  extractFooter?: boolean | undefined;
  /**
   * Granularity for confidence scores: 'word' (per-word scores) or 'page' (aggregate only). Defaults to None (no confidence scores) to keep response payload small.
   */
  confidenceScoresGranularity?: ConfidenceScoresGranularity | null | undefined;
};

/** @internal */
export type DocumentUnion$Outbound =
  | FileChunk$Outbound
  | DocumentURLChunk$Outbound
  | ImageURLChunk$Outbound;

/** @internal */
export const DocumentUnion$outboundSchema: z.ZodType<
  DocumentUnion$Outbound,
  DocumentUnion
> = smartUnion([
  FileChunk$outboundSchema,
  DocumentURLChunk$outboundSchema,
  ImageURLChunk$outboundSchema,
]);

export function documentUnionToJSON(documentUnion: DocumentUnion): string {
  return JSON.stringify(DocumentUnion$outboundSchema.parse(documentUnion));
}

/** @internal */
export type Pages$Outbound = string | Array<number>;

/** @internal */
export const Pages$outboundSchema: z.ZodType<Pages$Outbound, Pages> =
  smartUnion([z.string(), z.array(z.int())]);

export function pagesToJSON(pages: Pages): string {
  return JSON.stringify(Pages$outboundSchema.parse(pages));
}

/** @internal */
export const TableFormat$outboundSchema: z.ZodEnum<typeof TableFormat> = z.enum(
  TableFormat,
);

/** @internal */
export const ConfidenceScoresGranularity$outboundSchema: z.ZodEnum<
  typeof ConfidenceScoresGranularity
> = z.enum(ConfidenceScoresGranularity);

/** @internal */
export type OCRRequest$Outbound = {
  model: string | null;
  id?: string | undefined;
  document:
    | FileChunk$Outbound
    | DocumentURLChunk$Outbound
    | ImageURLChunk$Outbound;
  pages?: string | Array<number> | null | undefined;
  include_image_base64?: boolean | null | undefined;
  image_limit?: number | null | undefined;
  image_min_size?: number | null | undefined;
  bbox_annotation_format?: ResponseFormat$Outbound | null | undefined;
  document_annotation_format?: ResponseFormat$Outbound | null | undefined;
  document_annotation_prompt?: string | null | undefined;
  table_format?: string | null | undefined;
  extract_header?: boolean | undefined;
  extract_footer?: boolean | undefined;
  confidence_scores_granularity?: string | null | undefined;
};

/** @internal */
export const OCRRequest$outboundSchema: z.ZodType<
  OCRRequest$Outbound,
  OCRRequest
> = z.object({
  model: z.nullable(z.string()),
  id: z.string().optional(),
  document: smartUnion([
    FileChunk$outboundSchema,
    DocumentURLChunk$outboundSchema,
    ImageURLChunk$outboundSchema,
  ]),
  pages: z.nullable(smartUnion([z.string(), z.array(z.int())])).optional(),
  includeImageBase64: z.nullable(z.boolean()).optional(),
  imageLimit: z.nullable(z.int()).optional(),
  imageMinSize: z.nullable(z.int()).optional(),
  bboxAnnotationFormat: z.nullable(ResponseFormat$outboundSchema).optional(),
  documentAnnotationFormat: z.nullable(ResponseFormat$outboundSchema)
    .optional(),
  documentAnnotationPrompt: z.nullable(z.string()).optional(),
  tableFormat: z.nullable(TableFormat$outboundSchema).optional(),
  extractHeader: z.boolean().optional(),
  extractFooter: z.boolean().optional(),
  confidenceScoresGranularity: z.nullable(
    ConfidenceScoresGranularity$outboundSchema,
  ).optional(),
}).transform((v) => {
  return remap$(v, {
    includeImageBase64: "include_image_base64",
    imageLimit: "image_limit",
    imageMinSize: "image_min_size",
    bboxAnnotationFormat: "bbox_annotation_format",
    documentAnnotationFormat: "document_annotation_format",
    documentAnnotationPrompt: "document_annotation_prompt",
    tableFormat: "table_format",
    extractHeader: "extract_header",
    extractFooter: "extract_footer",
    confidenceScoresGranularity: "confidence_scores_granularity",
  });
});

export function ocrRequestToJSON(ocrRequest: OCRRequest): string {
  return JSON.stringify(OCRRequest$outboundSchema.parse(ocrRequest));
}
