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

import * as z from "zod/v3";
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 { OCRPageObject, OCRPageObject$inboundSchema } from "./ocrpageobject.js";
import { OCRUsageInfo, OCRUsageInfo$inboundSchema } from "./ocrusageinfo.js";

export type OCRResponse = {
  /**
   * List of OCR info for pages.
   */
  pages: Array<OCRPageObject>;
  /**
   * The model used to generate the OCR.
   */
  model: string;
  /**
   * Formatted response in the request_format if provided in json str
   */
  documentAnnotation?: string | null | undefined;
  usageInfo: OCRUsageInfo;
};

/** @internal */
export const OCRResponse$inboundSchema: z.ZodType<
  OCRResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  pages: z.array(OCRPageObject$inboundSchema),
  model: z.string(),
  document_annotation: z.nullable(z.string()).optional(),
  usage_info: OCRUsageInfo$inboundSchema,
}).transform((v) => {
  return remap$(v, {
    "document_annotation": "documentAnnotation",
    "usage_info": "usageInfo",
  });
});

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