/*
 * 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 { 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 ToolFileChunkTool = BuiltInConnectors | string;

export type ToolFileChunk = {
  type?: "tool_file" | undefined;
  tool: BuiltInConnectors | string;
  fileId: string;
  fileName?: string | null | undefined;
  fileType?: string | null | undefined;
};

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

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

export function toolFileChunkToolToJSON(
  toolFileChunkTool: ToolFileChunkTool,
): string {
  return JSON.stringify(
    ToolFileChunkTool$outboundSchema.parse(toolFileChunkTool),
  );
}
export function toolFileChunkToolFromJSON(
  jsonString: string,
): SafeParseResult<ToolFileChunkTool, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ToolFileChunkTool$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ToolFileChunkTool' from JSON`,
  );
}

/** @internal */
export const ToolFileChunk$inboundSchema: z.ZodType<
  ToolFileChunk,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("tool_file").default("tool_file"),
  tool: z.union([BuiltInConnectors$inboundSchema, z.string()]),
  file_id: z.string(),
  file_name: z.nullable(z.string()).optional(),
  file_type: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    "file_id": "fileId",
    "file_name": "fileName",
    "file_type": "fileType",
  });
});
/** @internal */
export type ToolFileChunk$Outbound = {
  type: "tool_file";
  tool: string | string;
  file_id: string;
  file_name?: string | null | undefined;
  file_type?: string | null | undefined;
};

/** @internal */
export const ToolFileChunk$outboundSchema: z.ZodType<
  ToolFileChunk$Outbound,
  z.ZodTypeDef,
  ToolFileChunk
> = z.object({
  type: z.literal("tool_file").default("tool_file" as const),
  tool: z.union([BuiltInConnectors$outboundSchema, z.string()]),
  fileId: z.string(),
  fileName: z.nullable(z.string()).optional(),
  fileType: z.nullable(z.string()).optional(),
}).transform((v) => {
  return remap$(v, {
    fileId: "file_id",
    fileName: "file_name",
    fileType: "file_type",
  });
});

export function toolFileChunkToJSON(toolFileChunk: ToolFileChunk): string {
  return JSON.stringify(ToolFileChunk$outboundSchema.parse(toolFileChunk));
}
export function toolFileChunkFromJSON(
  jsonString: string,
): SafeParseResult<ToolFileChunk, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => ToolFileChunk$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'ToolFileChunk' from JSON`,
  );
}
