/*
 * 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";

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,
  z.ZodTypeDef,
  unknown
> = z.union([z.record(z.any()), z.string()]);
/** @internal */
export type Arguments$Outbound = { [k: string]: any } | string;

/** @internal */
export const Arguments$outboundSchema: z.ZodType<
  Arguments$Outbound,
  z.ZodTypeDef,
  Arguments
> = z.union([z.record(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,
  z.ZodTypeDef,
  unknown
> = z.object({
  name: z.string(),
  arguments: z.union([z.record(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,
  z.ZodTypeDef,
  FunctionCall
> = z.object({
  name: z.string(),
  arguments: z.union([z.record(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`,
  );
}
