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

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 { 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, unknown> = openEnums
    .inboundSchema(CompletionResponseStreamChoiceFinishReason);

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