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

import * as z from "zod/v4";
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, unknown> = z
  .object({
    encoding: AudioEncoding$inboundSchema,
    sample_rate: z.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,
  AudioFormat
> = z.object({
  encoding: AudioEncoding$outboundSchema,
  sampleRate: z.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`,
  );
}
