/*
 * 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 TranscriptionStreamSegmentDelta = {
  type?: "transcription.segment" | undefined;
  text: string;
  start: number;
  end: number;
  speakerId?: string | null | undefined;
  additionalProperties?: { [k: string]: any } | undefined;
};

/** @internal */
export const TranscriptionStreamSegmentDelta$inboundSchema: z.ZodType<
  TranscriptionStreamSegmentDelta,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    type: z.literal("transcription.segment").default("transcription.segment"),
    text: z.string(),
    start: z.number(),
    end: z.number(),
    speaker_id: z.nullable(z.string()).optional(),
  }).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`,
  );
}
