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

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

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

export type AgentUpdateRequest = {
  /**
   * 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" })
      | (ImageGenerationTool & { type: "image_generation" })
      | (WebSearchTool & { type: "web_search" })
      | (WebSearchPremiumTool & { type: "web_search_premium" })
      | (DocumentLibraryTool & { type: "document_library" })
      | (FunctionTool & { type: "function" })
    >
    | undefined;
  /**
   * White-listed arguments from the completion API
   */
  completionArgs?: CompletionArgs | undefined;
  model?: string | null | undefined;
  name?: string | null | undefined;
  description?: string | null | undefined;
  handoffs?: Array<string> | null | undefined;
};

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

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

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

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace AgentUpdateRequestTools$ {
  /** @deprecated use `AgentUpdateRequestTools$inboundSchema` instead. */
  export const inboundSchema = AgentUpdateRequestTools$inboundSchema;
  /** @deprecated use `AgentUpdateRequestTools$outboundSchema` instead. */
  export const outboundSchema = AgentUpdateRequestTools$outboundSchema;
  /** @deprecated use `AgentUpdateRequestTools$Outbound` instead. */
  export type Outbound = AgentUpdateRequestTools$Outbound;
}

export function agentUpdateRequestToolsToJSON(
  agentUpdateRequestTools: AgentUpdateRequestTools,
): string {
  return JSON.stringify(
    AgentUpdateRequestTools$outboundSchema.parse(agentUpdateRequestTools),
  );
}

export function agentUpdateRequestToolsFromJSON(
  jsonString: string,
): SafeParseResult<AgentUpdateRequestTools, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AgentUpdateRequestTools$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AgentUpdateRequestTools' from JSON`,
  );
}

/** @internal */
export const AgentUpdateRequest$inboundSchema: z.ZodType<
  AgentUpdateRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  instructions: z.nullable(z.string()).optional(),
  tools: z.array(
    z.union([
      CodeInterpreterTool$inboundSchema.and(
        z.object({ type: z.literal("code_interpreter") }).transform((v) => ({
          type: v.type,
        })),
      ),
      ImageGenerationTool$inboundSchema.and(
        z.object({ type: z.literal("image_generation") }).transform((v) => ({
          type: v.type,
        })),
      ),
      WebSearchTool$inboundSchema.and(
        z.object({ type: z.literal("web_search") }).transform((v) => ({
          type: v.type,
        })),
      ),
      WebSearchPremiumTool$inboundSchema.and(
        z.object({ type: z.literal("web_search_premium") }).transform((v) => ({
          type: v.type,
        })),
      ),
      DocumentLibraryTool$inboundSchema.and(
        z.object({ type: z.literal("document_library") }).transform((v) => ({
          type: v.type,
        })),
      ),
      FunctionTool$inboundSchema.and(
        z.object({ type: z.literal("function") }).transform((v) => ({
          type: v.type,
        })),
      ),
    ]),
  ).optional(),
  completion_args: CompletionArgs$inboundSchema.optional(),
  model: z.nullable(z.string()).optional(),
  name: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
  handoffs: z.nullable(z.array(z.string())).optional(),
}).transform((v) => {
  return remap$(v, {
    "completion_args": "completionArgs",
  });
});

/** @internal */
export type AgentUpdateRequest$Outbound = {
  instructions?: string | null | undefined;
  tools?:
    | Array<
      | (CodeInterpreterTool$Outbound & { type: "code_interpreter" })
      | (ImageGenerationTool$Outbound & { type: "image_generation" })
      | (WebSearchTool$Outbound & { type: "web_search" })
      | (WebSearchPremiumTool$Outbound & { type: "web_search_premium" })
      | (DocumentLibraryTool$Outbound & { type: "document_library" })
      | (FunctionTool$Outbound & { type: "function" })
    >
    | undefined;
  completion_args?: CompletionArgs$Outbound | undefined;
  model?: string | null | undefined;
  name?: string | null | undefined;
  description?: string | null | undefined;
  handoffs?: Array<string> | null | undefined;
};

/** @internal */
export const AgentUpdateRequest$outboundSchema: z.ZodType<
  AgentUpdateRequest$Outbound,
  z.ZodTypeDef,
  AgentUpdateRequest
> = z.object({
  instructions: z.nullable(z.string()).optional(),
  tools: z.array(
    z.union([
      CodeInterpreterTool$outboundSchema.and(
        z.object({ type: z.literal("code_interpreter") }).transform((v) => ({
          type: v.type,
        })),
      ),
      ImageGenerationTool$outboundSchema.and(
        z.object({ type: z.literal("image_generation") }).transform((v) => ({
          type: v.type,
        })),
      ),
      WebSearchTool$outboundSchema.and(
        z.object({ type: z.literal("web_search") }).transform((v) => ({
          type: v.type,
        })),
      ),
      WebSearchPremiumTool$outboundSchema.and(
        z.object({ type: z.literal("web_search_premium") }).transform((v) => ({
          type: v.type,
        })),
      ),
      DocumentLibraryTool$outboundSchema.and(
        z.object({ type: z.literal("document_library") }).transform((v) => ({
          type: v.type,
        })),
      ),
      FunctionTool$outboundSchema.and(
        z.object({ type: z.literal("function") }).transform((v) => ({
          type: v.type,
        })),
      ),
    ]),
  ).optional(),
  completionArgs: CompletionArgs$outboundSchema.optional(),
  model: z.nullable(z.string()).optional(),
  name: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
  handoffs: z.nullable(z.array(z.string())).optional(),
}).transform((v) => {
  return remap$(v, {
    completionArgs: "completion_args",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace AgentUpdateRequest$ {
  /** @deprecated use `AgentUpdateRequest$inboundSchema` instead. */
  export const inboundSchema = AgentUpdateRequest$inboundSchema;
  /** @deprecated use `AgentUpdateRequest$outboundSchema` instead. */
  export const outboundSchema = AgentUpdateRequest$outboundSchema;
  /** @deprecated use `AgentUpdateRequest$Outbound` instead. */
  export type Outbound = AgentUpdateRequest$Outbound;
}

export function agentUpdateRequestToJSON(
  agentUpdateRequest: AgentUpdateRequest,
): string {
  return JSON.stringify(
    AgentUpdateRequest$outboundSchema.parse(agentUpdateRequest),
  );
}

export function agentUpdateRequestFromJSON(
  jsonString: string,
): SafeParseResult<AgentUpdateRequest, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => AgentUpdateRequest$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'AgentUpdateRequest' from JSON`,
  );
}
