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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  RealtimeTranscriptionErrorDetail,
  RealtimeTranscriptionErrorDetail$inboundSchema,
  RealtimeTranscriptionErrorDetail$Outbound,
  RealtimeTranscriptionErrorDetail$outboundSchema,
} from "./realtimetranscriptionerrordetail.js";

export type RealtimeTranscriptionError = {
  type?: "error" | undefined;
  error: RealtimeTranscriptionErrorDetail;
};

/** @internal */
export const RealtimeTranscriptionError$inboundSchema: z.ZodType<
  RealtimeTranscriptionError,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("error").default("error"),
  error: RealtimeTranscriptionErrorDetail$inboundSchema,
});
/** @internal */
export type RealtimeTranscriptionError$Outbound = {
  type: "error";
  error: RealtimeTranscriptionErrorDetail$Outbound;
};

/** @internal */
export const RealtimeTranscriptionError$outboundSchema: z.ZodType<
  RealtimeTranscriptionError$Outbound,
  z.ZodTypeDef,
  RealtimeTranscriptionError
> = z.object({
  type: z.literal("error").default("error" as const),
  error: RealtimeTranscriptionErrorDetail$outboundSchema,
});

export function realtimeTranscriptionErrorToJSON(
  realtimeTranscriptionError: RealtimeTranscriptionError,
): string {
  return JSON.stringify(
    RealtimeTranscriptionError$outboundSchema.parse(realtimeTranscriptionError),
  );
}
export function realtimeTranscriptionErrorFromJSON(
  jsonString: string,
): SafeParseResult<RealtimeTranscriptionError, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => RealtimeTranscriptionError$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'RealtimeTranscriptionError' from JSON`,
  );
}
