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

/**
 * The type of the value of this setting
 */
export enum SettingType {
  Bool = "bool",
  Int = "int",
  Text = "text",
  Double = "double",
}

/**
 * The default value of this setting
 */
export type Default = string | number | boolean;

/**
 * The current value of this setting
 */
export type Value = string | number | boolean;

/**
 * A configuration setting or preference
 */
export type Setting = {
  /**
   * The type of the value of this setting
   */
  type?: SettingType | undefined;
  /**
   * The default value of this setting
   */
  default?: string | number | boolean | undefined;
  /**
   * Whether the setting is considered advanced and normally hidden from the user
   */
  advanced?: boolean | undefined;
  /**
   * The possible values for this setting if restricted. The list is `|` separated with `value:name` entries.
   */
  enumValues?: string | undefined;
  /**
   * The group name of this setting to aid in display of a hierarchy
   */
  group?: string | undefined;
  /**
   * Whether the setting is hidden or not
   */
  hidden?: boolean | undefined;
  /**
   * The query parameter name for this setting
   */
  id?: string | undefined;
  /**
   * A user-friendly name for the setting
   */
  label?: string | undefined;
  /**
   * A description of the setting
   */
  summary?: string | undefined;
  /**
   * The current value of this setting
   */
  value?: string | number | boolean | undefined;
};

/** @internal */
export const SettingType$inboundSchema: z.ZodNativeEnum<typeof SettingType> = z
  .nativeEnum(SettingType);

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

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

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

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

/** @internal */
export const Setting$inboundSchema: z.ZodType<Setting, z.ZodTypeDef, unknown> =
  z.object({
    type: SettingType$inboundSchema.optional(),
    default: z.union([z.string(), z.number(), z.boolean()]).optional(),
    advanced: z.boolean().optional(),
    enumValues: z.string().optional(),
    group: z.string().optional(),
    hidden: z.boolean().optional(),
    id: z.string().optional(),
    label: z.string().optional(),
    summary: z.string().optional(),
    value: z.union([z.string(), z.number(), z.boolean()]).optional(),
  });

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