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

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

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

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

/** @internal */
export const TranscriptionSegmentChunk$outboundSchema: z.ZodType<
  TranscriptionSegmentChunk$Outbound,
  z.ZodTypeDef,
  TranscriptionSegmentChunk
> = z.object({
  text: z.string(),
  start: z.number(),
  end: z.number(),
  score: z.nullable(z.number()).optional(),
  speakerId: z.nullable(z.string()).optional(),
  type: Type$outboundSchema.default("transcription_segment"),
  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`,
  );
}
