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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  OCRConfidenceScore,
  OCRConfidenceScore$inboundSchema,
} from "./ocrconfidencescore.js";

/**
 * Format of the table
 */
export const Format = {
  Markdown: "markdown",
  Html: "html",
} as const;
/**
 * Format of the table
 */
export type Format = OpenEnum<typeof Format>;

export type OCRTableObject = {
  /**
   * Table ID for extracted table in a page
   */
  id: string;
  /**
   * Content of the table in the given format
   */
  content: string;
  /**
   * Format of the table
   */
  format: Format;
  /**
   * Per-word confidence scores for the table content. Returned when confidence_scores_granularity is set to 'word'.
   */
  wordConfidenceScores?: Array<OCRConfidenceScore> | null | undefined;
};

/** @internal */
export const Format$inboundSchema: z.ZodType<Format, unknown> = openEnums
  .inboundSchema(Format);

/** @internal */
export const OCRTableObject$inboundSchema: z.ZodType<OCRTableObject, unknown> =
  z.object({
    id: z.string(),
    content: z.string(),
    format: Format$inboundSchema,
    word_confidence_scores: z.nullable(
      z.array(OCRConfidenceScore$inboundSchema),
    ).optional(),
  }).transform((v) => {
    return remap$(v, {
      "word_confidence_scores": "wordConfidenceScores",
    });
  });

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