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

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

export type TranscriptionStreamDone = {
  model: string;
  text: string;
  segments?: Array<TranscriptionSegmentChunk> | undefined;
  usage: UsageInfo;
  type: "transcription.done";
  language: string | null;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const TranscriptionStreamDone$inboundSchema: z.ZodType<
  TranscriptionStreamDone,
  unknown
> = z.object({
  model: z.string(),
  text: z.string(),
  segments: z.array(TranscriptionSegmentChunk$inboundSchema).optional(),
  usage: UsageInfo$inboundSchema,
  type: z.literal("transcription.done"),
  language: z.nullable(z.string()),
}).catchall(z.any());
/** @internal */
export type TranscriptionStreamDone$Outbound = {
  model: string;
  text: string;
  segments?: Array<TranscriptionSegmentChunk$Outbound> | undefined;
  usage: UsageInfo$Outbound;
  type: "transcription.done";
  language: string | null;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const TranscriptionStreamDone$outboundSchema: z.ZodType<
  TranscriptionStreamDone$Outbound,
  TranscriptionStreamDone
> = z.object({
  model: z.string(),
  text: z.string(),
  segments: z.array(TranscriptionSegmentChunk$outboundSchema).optional(),
  usage: UsageInfo$outboundSchema,
  type: z.literal("transcription.done"),
  language: z.nullable(z.string()),
}).catchall(z.any());

export function transcriptionStreamDoneToJSON(
  transcriptionStreamDone: TranscriptionStreamDone,
): string {
  return JSON.stringify(
    TranscriptionStreamDone$outboundSchema.parse(transcriptionStreamDone),
  );
}
export function transcriptionStreamDoneFromJSON(
  jsonString: string,
): SafeParseResult<TranscriptionStreamDone, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => TranscriptionStreamDone$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'TranscriptionStreamDone' from JSON`,
  );
}
