/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 5a3dae5deeec
 */
import * as z from "zod/v4";
import { EventStream } from "../../lib/event-streams.js";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { discriminatedUnion } from "../../types/discriminatedUnion.js";
import { smartUnion } from "../../types/smartUnion.js";
import * as components from "../components/index.js";
/** @internal */
export const Data$inboundSchema = discriminatedUnion("type", {
    ["speech.audio.delta"]: components.SpeechStreamAudioDelta$inboundSchema,
    ["speech.audio.done"]: components.SpeechStreamDone$inboundSchema,
});
export function dataFromJSON(jsonString) {
    return safeParse(jsonString, (x) => Data$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Data' from JSON`);
}
/** @internal */
export const SpeechStreamEvents$inboundSchema = z.object({
    event: components.SpeechStreamEventTypes$inboundSchema,
    data: z.string().transform((v, ctx) => {
        try {
            return JSON.parse(v);
        }
        catch (err) {
            ctx.addIssue({
                input: v,
                code: "custom",
                message: `malformed json: ${err}`,
            });
            return z.NEVER;
        }
    }).pipe(discriminatedUnion("type", {
        ["speech.audio.delta"]: components.SpeechStreamAudioDelta$inboundSchema,
        ["speech.audio.done"]: components.SpeechStreamDone$inboundSchema,
    })),
});
export function speechStreamEventsFromJSON(jsonString) {
    return safeParse(jsonString, (x) => SpeechStreamEvents$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SpeechStreamEvents' from JSON`);
}
/** @internal */
export const SpeechResponse$inboundSchema = z.object({
    audio_data: z.string(),
}).transform((v) => {
    return remap$(v, {
        "audio_data": "audioData",
    });
});
export function speechResponseFromJSON(jsonString) {
    return safeParse(jsonString, (x) => SpeechResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SpeechResponse' from JSON`);
}
/** @internal */
export const SpeechV1AudioSpeechPostResponse$inboundSchema = smartUnion([
    z.lazy(() => SpeechResponse$inboundSchema),
    z.custom(x => x instanceof ReadableStream)
        .transform(stream => {
        return new EventStream(stream, rawEvent => {
            return {
                done: false,
                value: z.lazy(() => SpeechStreamEvents$inboundSchema).parse(rawEvent),
            };
        });
    }),
]);
export function speechV1AudioSpeechPostResponseFromJSON(jsonString) {
    return safeParse(jsonString, (x) => SpeechV1AudioSpeechPostResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'SpeechV1AudioSpeechPostResponse' from JSON`);
}
//# sourceMappingURL=speechv1audiospeechpost.js.map