/*
 * 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";

/**
 * Human-readable error message.
 */
export type Message = string | { [k: string]: any };

export type RealtimeTranscriptionErrorDetail = {
  /**
   * Human-readable error message.
   */
  message: string | { [k: string]: any };
  /**
   * Internal error code for debugging.
   */
  code: number;
};

/** @internal */
export const Message$inboundSchema: z.ZodType<Message, z.ZodTypeDef, unknown> =
  z.union([z.string(), z.record(z.any())]);
/** @internal */
export type Message$Outbound = string | { [k: string]: any };

/** @internal */
export const Message$outboundSchema: z.ZodType<
  Message$Outbound,
  z.ZodTypeDef,
  Message
> = z.union([z.string(), z.record(z.any())]);

export function messageToJSON(message: Message): string {
  return JSON.stringify(Message$outboundSchema.parse(message));
}
export function messageFromJSON(
  jsonString: string,
): SafeParseResult<Message, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Message$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Message' from JSON`,
  );
}

/** @internal */
export const RealtimeTranscriptionErrorDetail$inboundSchema: z.ZodType<
  RealtimeTranscriptionErrorDetail,
  z.ZodTypeDef,
  unknown
> = z.object({
  message: z.union([z.string(), z.record(z.any())]),
  code: z.number().int(),
});
/** @internal */
export type RealtimeTranscriptionErrorDetail$Outbound = {
  message: string | { [k: string]: any };
  code: number;
};

/** @internal */
export const RealtimeTranscriptionErrorDetail$outboundSchema: z.ZodType<
  RealtimeTranscriptionErrorDetail$Outbound,
  z.ZodTypeDef,
  RealtimeTranscriptionErrorDetail
> = z.object({
  message: z.union([z.string(), z.record(z.any())]),
  code: z.number().int(),
});

export function realtimeTranscriptionErrorDetailToJSON(
  realtimeTranscriptionErrorDetail: RealtimeTranscriptionErrorDetail,
): string {
  return JSON.stringify(
    RealtimeTranscriptionErrorDetail$outboundSchema.parse(
      realtimeTranscriptionErrorDetail,
    ),
  );
}
export function realtimeTranscriptionErrorDetailFromJSON(
  jsonString: string,
): SafeParseResult<RealtimeTranscriptionErrorDetail, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => RealtimeTranscriptionErrorDetail$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'RealtimeTranscriptionErrorDetail' from JSON`,
  );
}
