/*
 * 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 { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  AudioEncoding,
  AudioEncoding$inboundSchema,
  AudioEncoding$outboundSchema,
} from "./audioencoding.js";

export type AudioFormat = {
  encoding: AudioEncoding;
  sampleRate: number;
};

/** @internal */
export const AudioFormat$inboundSchema: z.ZodType<
  AudioFormat,
  z.ZodTypeDef,
  unknown
> = z.object({
  encoding: AudioEncoding$inboundSchema,
  sample_rate: z.number().int(),
}).transform((v) => {
  return remap$(v, {
    "sample_rate": "sampleRate",
  });
});
/** @internal */
export type AudioFormat$Outbound = {
  encoding: string;
  sample_rate: number;
};

/** @internal */
export const AudioFormat$outboundSchema: z.ZodType<
  AudioFormat$Outbound,
  z.ZodTypeDef,
  AudioFormat
> = z.object({
  encoding: AudioEncoding$outboundSchema,
  sampleRate: z.number().int(),
}).transform((v) => {
  return remap$(v, {
    sampleRate: "sample_rate",
  });
});

export function audioFormatToJSON(audioFormat: AudioFormat): string {
  return JSON.stringify(AudioFormat$outboundSchema.parse(audioFormat));
}
export function audioFormatFromJSON(
  jsonString: string,
): SafeParseResult<AudioFormat, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AudioFormat$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AudioFormat' from JSON`,
  );
}
