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

/** @internal */
export const TranscriptionSegmentChunk$inboundSchema: z.ZodType<
  TranscriptionSegmentChunk,
  z.ZodTypeDef,
  unknown
> = collectExtraKeys$(
  z.object({
    type: z.literal("transcription_segment").default("transcription_segment"),
    text: z.string(),
    start: z.number(),
    end: z.number(),
    score: z.nullable(z.number()).optional(),
    speaker_id: z.nullable(z.string()).optional(),
  }).catchall(z.any()),
  "additionalProperties",
  true,
).transform((v) => {
  return remap$(v, {
    "speaker_id": "speakerId",
  });
});
/** @internal */
export type TranscriptionSegmentChunk$Outbound = {
  type: "transcription_segment";
  text: string;
  start: number;
  end: number;
  score?: number | null | undefined;
  speaker_id?: string | null | undefined;
  [additionalProperties: string]: unknown;
};

/** @internal */
export const TranscriptionSegmentChunk$outboundSchema: z.ZodType<
  TranscriptionSegmentChunk$Outbound,
  z.ZodTypeDef,
  TranscriptionSegmentChunk
> = z.object({
  type: z.literal("transcription_segment").default(
    "transcription_segment" as const,
  ),
  text: z.string(),
  start: z.number(),
  end: z.number(),
  score: z.nullable(z.number()).optional(),
  speakerId: z.nullable(z.string()).optional(),
  additionalProperties: z.record(z.any()).optional(),
}).transform((v) => {
  return {
    ...v.additionalProperties,
    ...remap$(v, {
      speakerId: "speaker_id",
      additionalProperties: null,
    }),
  };
});

export function transcriptionSegmentChunkToJSON(
  transcriptionSegmentChunk: TranscriptionSegmentChunk,
): string {
  return JSON.stringify(
    TranscriptionSegmentChunk$outboundSchema.parse(transcriptionSegmentChunk),
  );
}
export function transcriptionSegmentChunkFromJSON(
  jsonString: string,
): SafeParseResult<TranscriptionSegmentChunk, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => TranscriptionSegmentChunk$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'TranscriptionSegmentChunk' from JSON`,
  );
}
