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

import * as z from "zod/v4";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  FunctionT,
  FunctionT$inboundSchema,
  FunctionT$Outbound,
  FunctionT$outboundSchema,
} from "./function.js";

export type FunctionTool = {
  type: "function";
  function: FunctionT;
};

/** @internal */
export const FunctionTool$inboundSchema: z.ZodType<FunctionTool, unknown> = z
  .object({
    type: z.literal("function"),
    function: FunctionT$inboundSchema,
  });
/** @internal */
export type FunctionTool$Outbound = {
  type: "function";
  function: FunctionT$Outbound;
};

/** @internal */
export const FunctionTool$outboundSchema: z.ZodType<
  FunctionTool$Outbound,
  FunctionTool
> = z.object({
  type: z.literal("function"),
  function: FunctionT$outboundSchema,
});

export function functionToolToJSON(functionTool: FunctionTool): string {
  return JSON.stringify(FunctionTool$outboundSchema.parse(functionTool));
}
export function functionToolFromJSON(
  jsonString: string,
): SafeParseResult<FunctionTool, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => FunctionTool$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'FunctionTool' from JSON`,
  );
}
