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

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

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

/** @internal */
export const ChatCompletionChoice$inboundSchema: z.ZodType<
  ChatCompletionChoice,
  z.ZodTypeDef,
  unknown
> = z.object({
  index: z.number().int(),
  message: AssistantMessage$inboundSchema,
  finish_reason: ChatCompletionChoiceFinishReason$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`,
  );
}
