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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  OCRImageObject,
  OCRImageObject$inboundSchema,
} from "./ocrimageobject.js";
import {
  OCRPageConfidenceScores,
  OCRPageConfidenceScores$inboundSchema,
} from "./ocrpageconfidencescores.js";
import {
  OCRPageDimensions,
  OCRPageDimensions$inboundSchema,
} from "./ocrpagedimensions.js";
import {
  OCRTableObject,
  OCRTableObject$inboundSchema,
} from "./ocrtableobject.js";

export type OCRPageObject = {
  /**
   * The page index in a pdf document starting from 0
   */
  index: number;
  /**
   * The markdown string response of the page
   */
  markdown: string;
  /**
   * List of all extracted images in the page
   */
  images: Array<OCRImageObject>;
  /**
   * List of all extracted tables in the page
   */
  tables?: Array<OCRTableObject> | undefined;
  /**
   * List of all hyperlinks in the page
   */
  hyperlinks?: Array<string> | undefined;
  /**
   * Header of the page
   */
  header?: string | null | undefined;
  /**
   * Footer of the page
   */
  footer?: string | null | undefined;
  /**
   * The dimensions of the PDF Page's screenshot image
   */
  dimensions: OCRPageDimensions | null;
  /**
   * Confidence scores for the OCR page (populated when confidence_scores_granularity is set)
   */
  confidenceScores?: OCRPageConfidenceScores | null | undefined;
};

/** @internal */
export const OCRPageObject$inboundSchema: z.ZodType<OCRPageObject, unknown> = z
  .object({
    index: z.int(),
    markdown: z.string(),
    images: z.array(OCRImageObject$inboundSchema),
    tables: z.array(OCRTableObject$inboundSchema).optional(),
    hyperlinks: z.array(z.string()).optional(),
    header: z.nullable(z.string()).optional(),
    footer: z.nullable(z.string()).optional(),
    dimensions: z.nullable(OCRPageDimensions$inboundSchema),
    confidence_scores: z.nullable(OCRPageConfidenceScores$inboundSchema)
      .optional(),
  }).transform((v) => {
    return remap$(v, {
      "confidence_scores": "confidenceScores",
    });
  });

export function ocrPageObjectFromJSON(
  jsonString: string,
): SafeParseResult<OCRPageObject, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => OCRPageObject$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'OCRPageObject' from JSON`,
  );
}
