/*
 * 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 {
  CodeInterpreterTool,
  CodeInterpreterTool$Outbound,
  CodeInterpreterTool$outboundSchema,
} from "./codeinterpretertool.js";
import {
  CompletionArgs,
  CompletionArgs$Outbound,
  CompletionArgs$outboundSchema,
} from "./completionargs.js";
import {
  ConversationInputs,
  ConversationInputs$Outbound,
  ConversationInputs$outboundSchema,
} from "./conversationinputs.js";
import {
  DocumentLibraryTool,
  DocumentLibraryTool$Outbound,
  DocumentLibraryTool$outboundSchema,
} from "./documentlibrarytool.js";
import {
  FunctionTool,
  FunctionTool$Outbound,
  FunctionTool$outboundSchema,
} from "./functiontool.js";
import {
  ImageGenerationTool,
  ImageGenerationTool$Outbound,
  ImageGenerationTool$outboundSchema,
} from "./imagegenerationtool.js";
import {
  WebSearchPremiumTool,
  WebSearchPremiumTool$Outbound,
  WebSearchPremiumTool$outboundSchema,
} from "./websearchpremiumtool.js";
import {
  WebSearchTool,
  WebSearchTool$Outbound,
  WebSearchTool$outboundSchema,
} from "./websearchtool.js";

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

export type Tools =
  | (CodeInterpreterTool & { type: "code_interpreter" })
  | (DocumentLibraryTool & { type: "document_library" })
  | (FunctionTool & { type: "function" })
  | (ImageGenerationTool & { type: "image_generation" })
  | (WebSearchTool & { type: "web_search" })
  | (WebSearchPremiumTool & { type: "web_search_premium" });

export type AgentVersion = string | number;

export type ConversationRequest = {
  inputs: ConversationInputs;
  stream?: boolean | undefined;
  store?: boolean | null | undefined;
  handoffExecution?: HandoffExecution | null | undefined;
  instructions?: string | null | undefined;
  /**
   * List of tools which are available to the model during the conversation.
   */
  tools?:
    | Array<
      | (CodeInterpreterTool & { type: "code_interpreter" })
      | (DocumentLibraryTool & { type: "document_library" })
      | (FunctionTool & { type: "function" })
      | (ImageGenerationTool & { type: "image_generation" })
      | (WebSearchTool & { type: "web_search" })
      | (WebSearchPremiumTool & { type: "web_search_premium" })
    >
    | undefined;
  completionArgs?: CompletionArgs | null | undefined;
  name?: string | null | undefined;
  description?: string | null | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  agentId?: string | null | undefined;
  agentVersion?: string | number | null | undefined;
  model?: string | null | undefined;
};

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

/** @internal */
export type Tools$Outbound =
  | (CodeInterpreterTool$Outbound & { type: "code_interpreter" })
  | (DocumentLibraryTool$Outbound & { type: "document_library" })
  | (FunctionTool$Outbound & { type: "function" })
  | (ImageGenerationTool$Outbound & { type: "image_generation" })
  | (WebSearchTool$Outbound & { type: "web_search" })
  | (WebSearchPremiumTool$Outbound & { type: "web_search_premium" });

/** @internal */
export const Tools$outboundSchema: z.ZodType<
  Tools$Outbound,
  z.ZodTypeDef,
  Tools
> = z.union([
  CodeInterpreterTool$outboundSchema.and(
    z.object({ type: z.literal("code_interpreter") }),
  ),
  DocumentLibraryTool$outboundSchema.and(
    z.object({ type: z.literal("document_library") }),
  ),
  FunctionTool$outboundSchema.and(z.object({ type: z.literal("function") })),
  ImageGenerationTool$outboundSchema.and(
    z.object({ type: z.literal("image_generation") }),
  ),
  WebSearchTool$outboundSchema.and(z.object({ type: z.literal("web_search") })),
  WebSearchPremiumTool$outboundSchema.and(
    z.object({ type: z.literal("web_search_premium") }),
  ),
]);

export function toolsToJSON(tools: Tools): string {
  return JSON.stringify(Tools$outboundSchema.parse(tools));
}

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

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

export function agentVersionToJSON(agentVersion: AgentVersion): string {
  return JSON.stringify(AgentVersion$outboundSchema.parse(agentVersion));
}

/** @internal */
export type ConversationRequest$Outbound = {
  inputs: ConversationInputs$Outbound;
  stream: boolean;
  store?: boolean | null | undefined;
  handoff_execution?: string | null | undefined;
  instructions?: string | null | undefined;
  tools?:
    | Array<
      | (CodeInterpreterTool$Outbound & { type: "code_interpreter" })
      | (DocumentLibraryTool$Outbound & { type: "document_library" })
      | (FunctionTool$Outbound & { type: "function" })
      | (ImageGenerationTool$Outbound & { type: "image_generation" })
      | (WebSearchTool$Outbound & { type: "web_search" })
      | (WebSearchPremiumTool$Outbound & { type: "web_search_premium" })
    >
    | undefined;
  completion_args?: CompletionArgs$Outbound | null | undefined;
  name?: string | null | undefined;
  description?: string | null | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  agent_id?: string | null | undefined;
  agent_version?: string | number | null | undefined;
  model?: string | null | undefined;
};

/** @internal */
export const ConversationRequest$outboundSchema: z.ZodType<
  ConversationRequest$Outbound,
  z.ZodTypeDef,
  ConversationRequest
> = z.object({
  inputs: ConversationInputs$outboundSchema,
  stream: z.boolean().default(false),
  store: z.nullable(z.boolean()).optional(),
  handoffExecution: z.nullable(HandoffExecution$outboundSchema).optional(),
  instructions: z.nullable(z.string()).optional(),
  tools: z.array(
    z.union([
      CodeInterpreterTool$outboundSchema.and(
        z.object({ type: z.literal("code_interpreter") }),
      ),
      DocumentLibraryTool$outboundSchema.and(
        z.object({ type: z.literal("document_library") }),
      ),
      FunctionTool$outboundSchema.and(
        z.object({ type: z.literal("function") }),
      ),
      ImageGenerationTool$outboundSchema.and(
        z.object({ type: z.literal("image_generation") }),
      ),
      WebSearchTool$outboundSchema.and(
        z.object({ type: z.literal("web_search") }),
      ),
      WebSearchPremiumTool$outboundSchema.and(
        z.object({ type: z.literal("web_search_premium") }),
      ),
    ]),
  ).optional(),
  completionArgs: z.nullable(CompletionArgs$outboundSchema).optional(),
  name: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
  metadata: z.nullable(z.record(z.any())).optional(),
  agentId: z.nullable(z.string()).optional(),
  agentVersion: z.nullable(z.union([z.string(), z.number().int()])).optional(),
  model: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    handoffExecution: "handoff_execution",
    completionArgs: "completion_args",
    agentId: "agent_id",
    agentVersion: "agent_version",
  });
});

export function conversationRequestToJSON(
  conversationRequest: ConversationRequest,
): string {
  return JSON.stringify(
    ConversationRequest$outboundSchema.parse(conversationRequest),
  );
}
