/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export const TranscriptionStreamTextDeltaType = {
  TranscriptionTextDelta: "transcription.text.delta",
} as const;
export type TranscriptionStreamTextDeltaType = ClosedEnum<
  typeof TranscriptionStreamTextDeltaType
>;

export type TranscriptionStreamTextDelta = {
  text: string;
  type?: TranscriptionStreamTextDeltaType | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const TranscriptionStreamTextDeltaType$inboundSchema: z.ZodNativeEnum<
  typeof TranscriptionStreamTextDeltaType
> = z.nativeEnum(TranscriptionStreamTextDeltaType);
/** @internal */
export const TranscriptionStreamTextDeltaType$outboundSchema: z.ZodNativeEnum<
  typeof TranscriptionStreamTextDeltaType
> = TranscriptionStreamTextDeltaType$inboundSchema;

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

/** @internal */
export const TranscriptionStreamTextDelta$outboundSchema: z.ZodType<
  TranscriptionStreamTextDelta$Outbound,
  z.ZodTypeDef,
  TranscriptionStreamTextDelta
> = z.object({
  text: z.string(),
  type: TranscriptionStreamTextDeltaType$outboundSchema.default(
    "transcription.text.delta",
  ),
  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`,
  );
}
