/*
 * 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 {
  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,
  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" | undefined;
  language: string | null;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const TranscriptionStreamDone$inboundSchema: z.ZodType<
  TranscriptionStreamDone,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    model: z.string(),
    text: z.string(),
    segments: z.array(TranscriptionSegmentChunk$inboundSchema).optional(),
    usage: UsageInfo$inboundSchema,
    type: z.literal("transcription.done").default("transcription.done"),
    language: z.nullable(z.string()),
  }).catchall(z.any()),
  "additionalProperties",
  true,
);
/** @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,
  z.ZodTypeDef,
  TranscriptionStreamDone
> = z.object({
  model: z.string(),
  text: z.string(),
  segments: z.array(TranscriptionSegmentChunk$outboundSchema).optional(),
  usage: UsageInfo$outboundSchema,
  type: z.literal("transcription.done").default("transcription.done" as const),
  language: z.nullable(z.string()),
  additionalProperties: z.record(z.any()).optional(),
}).transform((v) => {
  return {
    ...v.additionalProperties,
    ...remap$(v, {
      additionalProperties: null,
    }),
  };
});

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`,
  );
}
