/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import {
  CompletionArgs,
  CompletionArgs$Outbound,
  CompletionArgs$outboundSchema,
} from "./completionargs.js";
import {
  ConversationInputs,
  ConversationInputs$Outbound,
  ConversationInputs$outboundSchema,
} from "./conversationinputs.js";

export const ConversationRestartRequestHandoffExecution = {
  Client: "client",
  Server: "server",
} as const;
export type ConversationRestartRequestHandoffExecution = ClosedEnum<
  typeof ConversationRestartRequestHandoffExecution
>;

/**
 * Specific version of the agent to use when restarting. If not provided, uses the current version.
 */
export type ConversationRestartRequestAgentVersion = string | number;

/**
 * Request to restart a new conversation from a given entry in the conversation.
 */
export type ConversationRestartRequest = {
  inputs?: ConversationInputs | undefined;
  stream?: boolean | undefined;
  /**
   * Whether to store the results into our servers or not.
   */
  store?: boolean | undefined;
  handoffExecution?: ConversationRestartRequestHandoffExecution | undefined;
  /**
   * White-listed arguments from the completion API
   */
  completionArgs?: CompletionArgs | undefined;
  /**
   * Custom metadata for the conversation.
   */
  metadata?: { [k: string]: any } | null | undefined;
  fromEntryId: string;
  /**
   * Specific version of the agent to use when restarting. If not provided, uses the current version.
   */
  agentVersion?: string | number | null | undefined;
};

/** @internal */
export const ConversationRestartRequestHandoffExecution$outboundSchema:
  z.ZodNativeEnum<typeof ConversationRestartRequestHandoffExecution> = z
    .nativeEnum(ConversationRestartRequestHandoffExecution);

/** @internal */
export type ConversationRestartRequestAgentVersion$Outbound = string | number;

/** @internal */
export const ConversationRestartRequestAgentVersion$outboundSchema: z.ZodType<
  ConversationRestartRequestAgentVersion$Outbound,
  z.ZodTypeDef,
  ConversationRestartRequestAgentVersion
> = z.union([z.string(), z.number().int()]);

export function conversationRestartRequestAgentVersionToJSON(
  conversationRestartRequestAgentVersion:
    ConversationRestartRequestAgentVersion,
): string {
  return JSON.stringify(
    ConversationRestartRequestAgentVersion$outboundSchema.parse(
      conversationRestartRequestAgentVersion,
    ),
  );
}

/** @internal */
export type ConversationRestartRequest$Outbound = {
  inputs?: ConversationInputs$Outbound | undefined;
  stream: boolean;
  store: boolean;
  handoff_execution: string;
  completion_args?: CompletionArgs$Outbound | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  from_entry_id: string;
  agent_version?: string | number | null | undefined;
};

/** @internal */
export const ConversationRestartRequest$outboundSchema: z.ZodType<
  ConversationRestartRequest$Outbound,
  z.ZodTypeDef,
  ConversationRestartRequest
> = z.object({
  inputs: ConversationInputs$outboundSchema.optional(),
  stream: z.boolean().default(false),
  store: z.boolean().default(true),
  handoffExecution: ConversationRestartRequestHandoffExecution$outboundSchema
    .default("server"),
  completionArgs: CompletionArgs$outboundSchema.optional(),
  metadata: z.nullable(z.record(z.any())).optional(),
  fromEntryId: z.string(),
  agentVersion: z.nullable(z.union([z.string(), z.number().int()])).optional(),
}).transform((v) => {
  return remap$(v, {
    handoffExecution: "handoff_execution",
    completionArgs: "completion_args",
    fromEntryId: "from_entry_id",
    agentVersion: "agent_version",
  });
});

export function conversationRestartRequestToJSON(
  conversationRestartRequest: ConversationRestartRequest,
): string {
  return JSON.stringify(
    ConversationRestartRequest$outboundSchema.parse(conversationRestartRequest),
  );
}
