/*
 * 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 CompletionResponseStreamChoiceFinishReason = {
  Stop: "stop",
  Length: "length",
  Error: "error",
  ToolCalls: "tool_calls",
} as const;
export type CompletionResponseStreamChoiceFinishReason = OpenEnum<
  typeof CompletionResponseStreamChoiceFinishReason
>;

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

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

/** @internal */
export const CompletionResponseStreamChoice$inboundSchema: z.ZodType<
  CompletionResponseStreamChoice,
  z.ZodTypeDef,
  unknown
> = z.object({
  index: z.number().int(),
  delta: DeltaMessage$inboundSchema,
  finish_reason: z.nullable(
    CompletionResponseStreamChoiceFinishReason$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`,
  );
}
