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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  CompletionArgsStop,
  CompletionArgsStop$inboundSchema,
  CompletionArgsStop$Outbound,
  CompletionArgsStop$outboundSchema,
} from "./completionargsstop.js";
import {
  Prediction,
  Prediction$inboundSchema,
  Prediction$Outbound,
  Prediction$outboundSchema,
} from "./prediction.js";
import {
  ReasoningEffort,
  ReasoningEffort$inboundSchema,
  ReasoningEffort$outboundSchema,
} from "./reasoningeffort.js";
import {
  ResponseFormat,
  ResponseFormat$inboundSchema,
  ResponseFormat$Outbound,
  ResponseFormat$outboundSchema,
} from "./responseformat.js";
import {
  ToolChoiceEnum,
  ToolChoiceEnum$inboundSchema,
  ToolChoiceEnum$outboundSchema,
} from "./toolchoiceenum.js";

/**
 * White-listed arguments from the completion API
 */
export type CompletionArgs = {
  stop?: CompletionArgsStop | null | undefined;
  presencePenalty?: number | null | undefined;
  frequencyPenalty?: number | null | undefined;
  temperature?: number | null | undefined;
  topP?: number | null | undefined;
  maxTokens?: number | null | undefined;
  randomSeed?: number | null | undefined;
  prediction?: Prediction | null | undefined;
  responseFormat?: ResponseFormat | null | undefined;
  toolChoice?: ToolChoiceEnum | undefined;
  reasoningEffort?: ReasoningEffort | null | undefined;
};

/** @internal */
export const CompletionArgs$inboundSchema: z.ZodType<CompletionArgs, unknown> =
  z.object({
    stop: z.nullable(CompletionArgsStop$inboundSchema).optional(),
    presence_penalty: z.nullable(z.number()).optional(),
    frequency_penalty: z.nullable(z.number()).optional(),
    temperature: z.nullable(z.number()).optional(),
    top_p: z.nullable(z.number()).optional(),
    max_tokens: z.nullable(z.int()).optional(),
    random_seed: z.nullable(z.int()).optional(),
    prediction: z.nullable(Prediction$inboundSchema).optional(),
    response_format: z.nullable(ResponseFormat$inboundSchema).optional(),
    tool_choice: ToolChoiceEnum$inboundSchema.optional(),
    reasoning_effort: z.nullable(ReasoningEffort$inboundSchema).optional(),
  }).transform((v) => {
    return remap$(v, {
      "presence_penalty": "presencePenalty",
      "frequency_penalty": "frequencyPenalty",
      "top_p": "topP",
      "max_tokens": "maxTokens",
      "random_seed": "randomSeed",
      "response_format": "responseFormat",
      "tool_choice": "toolChoice",
      "reasoning_effort": "reasoningEffort",
    });
  });
/** @internal */
export type CompletionArgs$Outbound = {
  stop?: CompletionArgsStop$Outbound | null | undefined;
  presence_penalty?: number | null | undefined;
  frequency_penalty?: number | null | undefined;
  temperature?: number | null | undefined;
  top_p?: number | null | undefined;
  max_tokens?: number | null | undefined;
  random_seed?: number | null | undefined;
  prediction?: Prediction$Outbound | null | undefined;
  response_format?: ResponseFormat$Outbound | null | undefined;
  tool_choice?: string | undefined;
  reasoning_effort?: string | null | undefined;
};

/** @internal */
export const CompletionArgs$outboundSchema: z.ZodType<
  CompletionArgs$Outbound,
  CompletionArgs
> = z.object({
  stop: z.nullable(CompletionArgsStop$outboundSchema).optional(),
  presencePenalty: z.nullable(z.number()).optional(),
  frequencyPenalty: z.nullable(z.number()).optional(),
  temperature: z.nullable(z.number()).optional(),
  topP: z.nullable(z.number()).optional(),
  maxTokens: z.nullable(z.int()).optional(),
  randomSeed: z.nullable(z.int()).optional(),
  prediction: z.nullable(Prediction$outboundSchema).optional(),
  responseFormat: z.nullable(ResponseFormat$outboundSchema).optional(),
  toolChoice: ToolChoiceEnum$outboundSchema.optional(),
  reasoningEffort: z.nullable(ReasoningEffort$outboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    presencePenalty: "presence_penalty",
    frequencyPenalty: "frequency_penalty",
    topP: "top_p",
    maxTokens: "max_tokens",
    randomSeed: "random_seed",
    responseFormat: "response_format",
    toolChoice: "tool_choice",
    reasoningEffort: "reasoning_effort",
  });
});

export function completionArgsToJSON(completionArgs: CompletionArgs): string {
  return JSON.stringify(CompletionArgs$outboundSchema.parse(completionArgs));
}
export function completionArgsFromJSON(
  jsonString: string,
): SafeParseResult<CompletionArgs, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CompletionArgs$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CompletionArgs' from JSON`,
  );
}
