/*
 * 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 {
  AssistantMessage,
  AssistantMessage$inboundSchema,
} from "./assistantmessage.js";

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

export type ChatCompletionChoice = {
  index: number;
  message: AssistantMessage;
  finishReason: FinishReason;
};

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

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

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