/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: 0a4e01a259af
 */

import * as z from "zod/v4";
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";
import { DeltaMessage, DeltaMessage$inboundSchema } from "./deltamessage.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 | undefined;
  messages?: Array<DeltaMessage> | undefined;
  finishReason: ChatCompletionChoiceFinishReason;
};

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

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