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

import * as z from "zod/v4";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { smartUnion } from "../../types/smartUnion.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type Arguments = { [k: string]: any } | string;

export type FunctionCall = {
  name: string;
  arguments: { [k: string]: any } | string;
};

/** @internal */
export const Arguments$inboundSchema: z.ZodType<Arguments, unknown> =
  smartUnion([z.record(z.string(), z.any()), z.string()]);
/** @internal */
export type Arguments$Outbound = { [k: string]: any } | string;

/** @internal */
export const Arguments$outboundSchema: z.ZodType<
  Arguments$Outbound,
  Arguments
> = smartUnion([z.record(z.string(), z.any()), z.string()]);

export function argumentsToJSON(value: Arguments): string {
  return JSON.stringify(Arguments$outboundSchema.parse(value));
}
export function argumentsFromJSON(
  jsonString: string,
): SafeParseResult<Arguments, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Arguments$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Arguments' from JSON`,
  );
}

/** @internal */
export const FunctionCall$inboundSchema: z.ZodType<FunctionCall, unknown> = z
  .object({
    name: z.string(),
    arguments: smartUnion([z.record(z.string(), z.any()), z.string()]),
  });
/** @internal */
export type FunctionCall$Outbound = {
  name: string;
  arguments: { [k: string]: any } | string;
};

/** @internal */
export const FunctionCall$outboundSchema: z.ZodType<
  FunctionCall$Outbound,
  FunctionCall
> = z.object({
  name: z.string(),
  arguments: smartUnion([z.record(z.string(), z.any()), z.string()]),
});

export function functionCallToJSON(functionCall: FunctionCall): string {
  return JSON.stringify(FunctionCall$outboundSchema.parse(functionCall));
}
export function functionCallFromJSON(
  jsonString: string,
): SafeParseResult<FunctionCall, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => FunctionCall$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'FunctionCall' from JSON`,
  );
}
