/*
 * 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 TranscriptionStreamSegmentDeltaType = {
  TranscriptionSegment: "transcription.segment",
} as const;
export type TranscriptionStreamSegmentDeltaType = ClosedEnum<
  typeof TranscriptionStreamSegmentDeltaType
>;

export type TranscriptionStreamSegmentDelta = {
  text: string;
  start: number;
  end: number;
  speakerId?: string | null | undefined;
  type: TranscriptionStreamSegmentDeltaType | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

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

/** @internal */
export const TranscriptionStreamSegmentDelta$inboundSchema: z.ZodType<
  TranscriptionStreamSegmentDelta,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    text: z.string(),
    start: z.number(),
    end: z.number(),
    speaker_id: z.nullable(z.string()).optional(),
    type: TranscriptionStreamSegmentDeltaType$inboundSchema.default(
      "transcription.segment",
    ),
  }).catchall(z.any()),
  "additionalProperties",
  true,
).transform((v) => {
  return remap$(v, {
    "speaker_id": "speakerId",
  });
});

export function transcriptionStreamSegmentDeltaFromJSON(
  jsonString: string,
): SafeParseResult<TranscriptionStreamSegmentDelta, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => TranscriptionStreamSegmentDelta$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'TranscriptionStreamSegmentDelta' from JSON`,
  );
}
