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

import * as z from "zod/v4";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import * as discriminatedUnionTypes from "../../types/discriminatedUnion.js";
import { discriminatedUnion } from "../../types/discriminatedUnion.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  CodeInterpreterTool,
  CodeInterpreterTool$inboundSchema,
} from "./codeinterpretertool.js";
import {
  CompletionArgs,
  CompletionArgs$inboundSchema,
} from "./completionargs.js";
import {
  CustomConnector,
  CustomConnector$inboundSchema,
} from "./customconnector.js";
import {
  DocumentLibraryTool,
  DocumentLibraryTool$inboundSchema,
} from "./documentlibrarytool.js";
import { FunctionTool, FunctionTool$inboundSchema } from "./functiontool.js";
import {
  GuardrailConfig,
  GuardrailConfig$inboundSchema,
} from "./guardrailconfig.js";
import {
  ImageGenerationTool,
  ImageGenerationTool$inboundSchema,
} from "./imagegenerationtool.js";
import {
  WebSearchPremiumTool,
  WebSearchPremiumTool$inboundSchema,
} from "./websearchpremiumtool.js";
import { WebSearchTool, WebSearchTool$inboundSchema } from "./websearchtool.js";

export type ModelConversationTool =
  | CodeInterpreterTool
  | CustomConnector
  | DocumentLibraryTool
  | FunctionTool
  | ImageGenerationTool
  | WebSearchTool
  | WebSearchPremiumTool
  | discriminatedUnionTypes.Unknown<"type">;

export type ModelConversation = {
  /**
   * 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
      | CustomConnector
      | DocumentLibraryTool
      | FunctionTool
      | ImageGenerationTool
      | WebSearchTool
      | WebSearchPremiumTool
      | discriminatedUnionTypes.Unknown<"type">
    >
    | undefined;
  /**
   * White-listed arguments from the completion API
   */
  completionArgs?: CompletionArgs | undefined;
  guardrails?: Array<GuardrailConfig> | null | undefined;
  /**
   * Name given to the conversation.
   */
  name?: string | null | undefined;
  /**
   * Description of the what the conversation is about.
   */
  description?: string | null | undefined;
  /**
   * Custom metadata for the conversation.
   */
  metadata?: { [k: string]: any } | null | undefined;
  object: "conversation";
  id: string;
  createdAt: Date;
  updatedAt: Date;
  model: string;
};

/** @internal */
export const ModelConversationTool$inboundSchema: z.ZodType<
  ModelConversationTool,
  unknown
> = discriminatedUnion("type", {
  code_interpreter: CodeInterpreterTool$inboundSchema,
  connector: CustomConnector$inboundSchema,
  document_library: DocumentLibraryTool$inboundSchema,
  function: FunctionTool$inboundSchema,
  image_generation: ImageGenerationTool$inboundSchema,
  web_search: WebSearchTool$inboundSchema,
  web_search_premium: WebSearchPremiumTool$inboundSchema,
});

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

/** @internal */
export const ModelConversation$inboundSchema: z.ZodType<
  ModelConversation,
  unknown
> = z.object({
  instructions: z.nullable(z.string()).optional(),
  tools: z.array(discriminatedUnion("type", {
    code_interpreter: CodeInterpreterTool$inboundSchema,
    connector: CustomConnector$inboundSchema,
    document_library: DocumentLibraryTool$inboundSchema,
    function: FunctionTool$inboundSchema,
    image_generation: ImageGenerationTool$inboundSchema,
    web_search: WebSearchTool$inboundSchema,
    web_search_premium: WebSearchPremiumTool$inboundSchema,
  })).optional(),
  completion_args: CompletionArgs$inboundSchema.optional(),
  guardrails: z.nullable(z.array(GuardrailConfig$inboundSchema)).optional(),
  name: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
  metadata: z.nullable(z.record(z.string(), z.any())).optional(),
  object: z.literal("conversation").default("conversation"),
  id: z.string(),
  created_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  updated_at: z.iso.datetime({ offset: true }).transform(v => new Date(v)),
  model: z.string(),
}).transform((v) => {
  return remap$(v, {
    "completion_args": "completionArgs",
    "created_at": "createdAt",
    "updated_at": "updatedAt",
  });
});

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