/*
 * 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 {
  CodeInterpreterTool,
  CodeInterpreterTool$Outbound,
  CodeInterpreterTool$outboundSchema,
} from "./codeinterpretertool.js";
import {
  CompletionArgs,
  CompletionArgs$Outbound,
  CompletionArgs$outboundSchema,
} from "./completionargs.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 type AgentCreationRequestTools =
  | (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 AgentCreationRequest = {
  /**
   * Instruction prompt the model will follow during the conversation.
   */
  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;
  /**
   * White-listed arguments from the completion API
   */
  completionArgs?: CompletionArgs | undefined;
  model: string;
  name: string;
  description?: string | null | undefined;
  handoffs?: Array<string> | null | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  versionMessage?: string | null | undefined;
};

/** @internal */
export type AgentCreationRequestTools$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 AgentCreationRequestTools$outboundSchema: z.ZodType<
  AgentCreationRequestTools$Outbound,
  z.ZodTypeDef,
  AgentCreationRequestTools
> = 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 agentCreationRequestToolsToJSON(
  agentCreationRequestTools: AgentCreationRequestTools,
): string {
  return JSON.stringify(
    AgentCreationRequestTools$outboundSchema.parse(agentCreationRequestTools),
  );
}

/** @internal */
export type AgentCreationRequest$Outbound = {
  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 | undefined;
  model: string;
  name: string;
  description?: string | null | undefined;
  handoffs?: Array<string> | null | undefined;
  metadata?: { [k: string]: any } | null | undefined;
  version_message?: string | null | undefined;
};

/** @internal */
export const AgentCreationRequest$outboundSchema: z.ZodType<
  AgentCreationRequest$Outbound,
  z.ZodTypeDef,
  AgentCreationRequest
> = z.object({
  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: CompletionArgs$outboundSchema.optional(),
  model: z.string(),
  name: z.string(),
  description: z.nullable(z.string()).optional(),
  handoffs: z.nullable(z.array(z.string())).optional(),
  metadata: z.nullable(z.record(z.any())).optional(),
  versionMessage: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    completionArgs: "completion_args",
    versionMessage: "version_message",
  });
});

export function agentCreationRequestToJSON(
  agentCreationRequest: AgentCreationRequest,
): string {
  return JSON.stringify(
    AgentCreationRequest$outboundSchema.parse(agentCreationRequest),
  );
}
