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

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

export type CustomProperty =
  | string
  | number
  | boolean
  | { [k: string]: any }
  | Array<any>;

/** @internal */
export const CustomProperty$inboundSchema: z.ZodType<
  CustomProperty,
  z.ZodTypeDef,
  unknown
> = z.union([
  z.string(),
  z.number(),
  z.boolean(),
  z.record(z.any()),
  z.array(z.any()),
]);

/** @internal */
export type CustomProperty$Outbound = string | number | boolean | {
  [k: string]: any;
} | Array<any>;

/** @internal */
export const CustomProperty$outboundSchema: z.ZodType<
  CustomProperty$Outbound,
  z.ZodTypeDef,
  CustomProperty
> = z.union([
  z.string(),
  z.number(),
  z.boolean(),
  z.record(z.any()),
  z.array(z.any()),
]);

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace CustomProperty$ {
  /** @deprecated use `CustomProperty$inboundSchema` instead. */
  export const inboundSchema = CustomProperty$inboundSchema;
  /** @deprecated use `CustomProperty$outboundSchema` instead. */
  export const outboundSchema = CustomProperty$outboundSchema;
  /** @deprecated use `CustomProperty$Outbound` instead. */
  export type Outbound = CustomProperty$Outbound;
}

export function customPropertyToJSON(customProperty: CustomProperty): string {
  return JSON.stringify(CustomProperty$outboundSchema.parse(customProperty));
}

export function customPropertyFromJSON(
  jsonString: string,
): SafeParseResult<CustomProperty, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => CustomProperty$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'CustomProperty' from JSON`,
  );
}
