/*
 * 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 { ClosedEnum } from "../../types/enums.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 const ToolFileChunkType = {
  ToolFile: "tool_file",
} as const;
export type ToolFileChunkType = ClosedEnum<typeof ToolFileChunkType>;

export type ToolFileChunkTool = BuiltInConnectors | string;

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

/** @internal */
export const ToolFileChunkType$inboundSchema: z.ZodNativeEnum<
  typeof ToolFileChunkType
> = z.nativeEnum(ToolFileChunkType);
/** @internal */
export const ToolFileChunkType$outboundSchema: z.ZodNativeEnum<
  typeof ToolFileChunkType
> = ToolFileChunkType$inboundSchema;

/** @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: ToolFileChunkType$inboundSchema.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: string;
  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: ToolFileChunkType$outboundSchema.default("tool_file"),
  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`,
  );
}
