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

import * as z from "zod/v3";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  BuiltInConnectors,
  BuiltInConnectors$inboundSchema,
  BuiltInConnectors$outboundSchema,
} from "./builtinconnectors.js";

export type ToolReferenceChunkTool = BuiltInConnectors | string;

export type ToolReferenceChunk = {
  type?: "tool_reference" | undefined;
  tool: BuiltInConnectors | string;
  title: string;
  url?: string | null | undefined;
  favicon?: string | null | undefined;
  description?: string | null | undefined;
};

/** @internal */
export const ToolReferenceChunkTool$inboundSchema: z.ZodType<
  ToolReferenceChunkTool,
  z.ZodTypeDef,
  unknown
> = z.union([BuiltInConnectors$inboundSchema, z.string()]);
/** @internal */
export type ToolReferenceChunkTool$Outbound = string | string;

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

export function toolReferenceChunkToolToJSON(
  toolReferenceChunkTool: ToolReferenceChunkTool,
): string {
  return JSON.stringify(
    ToolReferenceChunkTool$outboundSchema.parse(toolReferenceChunkTool),
  );
}
export function toolReferenceChunkToolFromJSON(
  jsonString: string,
): SafeParseResult<ToolReferenceChunkTool, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ToolReferenceChunkTool$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ToolReferenceChunkTool' from JSON`,
  );
}

/** @internal */
export const ToolReferenceChunk$inboundSchema: z.ZodType<
  ToolReferenceChunk,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("tool_reference").default("tool_reference"),
  tool: z.union([BuiltInConnectors$inboundSchema, z.string()]),
  title: z.string(),
  url: z.nullable(z.string()).optional(),
  favicon: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
});
/** @internal */
export type ToolReferenceChunk$Outbound = {
  type: "tool_reference";
  tool: string | string;
  title: string;
  url?: string | null | undefined;
  favicon?: string | null | undefined;
  description?: string | null | undefined;
};

/** @internal */
export const ToolReferenceChunk$outboundSchema: z.ZodType<
  ToolReferenceChunk$Outbound,
  z.ZodTypeDef,
  ToolReferenceChunk
> = z.object({
  type: z.literal("tool_reference").default("tool_reference" as const),
  tool: z.union([BuiltInConnectors$outboundSchema, z.string()]),
  title: z.string(),
  url: z.nullable(z.string()).optional(),
  favicon: z.nullable(z.string()).optional(),
  description: z.nullable(z.string()).optional(),
});

export function toolReferenceChunkToJSON(
  toolReferenceChunk: ToolReferenceChunk,
): string {
  return JSON.stringify(
    ToolReferenceChunk$outboundSchema.parse(toolReferenceChunk),
  );
}
export function toolReferenceChunkFromJSON(
  jsonString: string,
): SafeParseResult<ToolReferenceChunk, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ToolReferenceChunk$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ToolReferenceChunk' from JSON`,
  );
}
