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

export type TranscriptionStreamTextDelta = {
  type?: "transcription.text.delta" | undefined;
  text: string;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const TranscriptionStreamTextDelta$inboundSchema: z.ZodType<
  TranscriptionStreamTextDelta,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    type: z.literal("transcription.text.delta").default(
      "transcription.text.delta",
    ),
    text: z.string(),
  }).catchall(z.any()),
  "additionalProperties",
  true,
);
/** @internal */
export type TranscriptionStreamTextDelta$Outbound = {
  type: "transcription.text.delta";
  text: string;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const TranscriptionStreamTextDelta$outboundSchema: z.ZodType<
  TranscriptionStreamTextDelta$Outbound,
  z.ZodTypeDef,
  TranscriptionStreamTextDelta
> = z.object({
  type: z.literal("transcription.text.delta").default(
    "transcription.text.delta" as const,
  ),
  text: z.string(),
  additionalProperties: z.record(z.any()).optional(),
}).transform((v) => {
  return {
    ...v.additionalProperties,
    ...remap$(v, {
      additionalProperties: null,
    }),
  };
});

export function transcriptionStreamTextDeltaToJSON(
  transcriptionStreamTextDelta: TranscriptionStreamTextDelta,
): string {
  return JSON.stringify(
    TranscriptionStreamTextDelta$outboundSchema.parse(
      transcriptionStreamTextDelta,
    ),
  );
}
export function transcriptionStreamTextDeltaFromJSON(
  jsonString: string,
): SafeParseResult<TranscriptionStreamTextDelta, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => TranscriptionStreamTextDelta$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'TranscriptionStreamTextDelta' from JSON`,
  );
}
