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

import * as z from "zod/v3";
import {
  collectExtraKeys as collectExtraKeys$,
  safeParse,
} from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  TranscriptionSegmentChunk,
  TranscriptionSegmentChunk$inboundSchema,
} from "./transcriptionsegmentchunk.js";
import { UsageInfo, UsageInfo$inboundSchema } from "./usageinfo.js";

export type TranscriptionResponse = {
  model: string;
  text: string;
  segments?: Array<TranscriptionSegmentChunk> | undefined;
  usage: UsageInfo;
  language: string | null;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const TranscriptionResponse$inboundSchema: z.ZodType<
  TranscriptionResponse,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    model: z.string(),
    text: z.string(),
    segments: z.array(TranscriptionSegmentChunk$inboundSchema).optional(),
    usage: UsageInfo$inboundSchema,
    language: z.nullable(z.string()),
  }).catchall(z.any()),
  "additionalProperties",
  true,
);

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