/*
 * 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 * as types from "../types/primitives.js";
import { smartUnion } from "../types/smartUnion.js";
import { SDKValidationError } from "./sdkvalidationerror.js";

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

/** @internal */
export const FlagJSONValue$inboundSchema: z.ZodType<
  FlagJSONValue,
  z.ZodTypeDef,
  unknown
> = smartUnion([
  types.string(),
  types.number(),
  z.array(types.nullable(z.lazy(() => FlagJSONValue$inboundSchema))),
  z.record(types.nullable(z.lazy(() => FlagJSONValue$inboundSchema))),
  types.boolean(),
]);

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