/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v3";
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 {
  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;
};

/** @internal */
export const OCRPageObject$inboundSchema: z.ZodType<
  OCRPageObject,
  z.ZodTypeDef,
  unknown
> = z.object({
  index: z.number().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),
});

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