/*
 * 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 { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import { DeltaMessage, DeltaMessage$inboundSchema } from "./deltamessage.js";

export const FinishReason = {
  Stop: "stop",
  Length: "length",
  Error: "error",
  ToolCalls: "tool_calls",
} as const;
export type FinishReason = OpenEnum<typeof FinishReason>;

export type CompletionResponseStreamChoice = {
  index: number;
  delta: DeltaMessage;
  finishReason: FinishReason | null;
};

/** @internal */
export const FinishReason$inboundSchema: z.ZodType<
  FinishReason,
  z.ZodTypeDef,
  unknown
> = openEnums.inboundSchema(FinishReason);

/** @internal */
export const CompletionResponseStreamChoice$inboundSchema: z.ZodType<
  CompletionResponseStreamChoice,
  z.ZodTypeDef,
  unknown
> = z.object({
  index: z.number().int(),
  delta: DeltaMessage$inboundSchema,
  finish_reason: z.nullable(FinishReason$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "finish_reason": "finishReason",
  });
});

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