var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/systemSettings/registry/utils/typeValidation.ts
var typeValidation_exports = {};
__export(typeValidation_exports, {
  parseDefaultValue: () => parseDefaultValue,
  validateDefaultValue: () => validateDefaultValue
});
module.exports = __toCommonJS(typeValidation_exports);
var validateString = (value) => {
  if (value === null || value === void 0 || value === "") {
    return { isValid: true };
  }
  if (typeof value === "string") {
    return { isValid: true };
  }
  return {
    isValid: false,
    error: "默认值必须是字符串类型"
  };
};
var validateInteger = (value) => {
  if (value === null || value === void 0 || value === "") {
    return { isValid: true };
  }
  if (typeof value === "number") {
    if (!Number.isInteger(value)) {
      return {
        isValid: false,
        error: "默认值必须是整数"
      };
    }
    return { isValid: true };
  }
  if (typeof value === "string") {
    const trimmed = value.trim();
    if (trimmed === "") {
      return { isValid: true };
    }
    const num = Number(trimmed);
    if (isNaN(num) || !Number.isInteger(num)) {
      return {
        isValid: false,
        error: "默认值必须是有效的整数"
      };
    }
    return { isValid: true };
  }
  return {
    isValid: false,
    error: "默认值必须是有效的整数"
  };
};
var validateFloat = (value) => {
  if (value === null || value === void 0 || value === "") {
    return { isValid: true };
  }
  if (typeof value === "number") {
    if (!isFinite(value)) {
      return {
        isValid: false,
        error: "默认值必须是有效的数字"
      };
    }
    return { isValid: true };
  }
  if (typeof value === "string") {
    const trimmed = value.trim();
    if (trimmed === "") {
      return { isValid: true };
    }
    const num = Number(trimmed);
    if (isNaN(num) || !isFinite(num)) {
      return {
        isValid: false,
        error: "默认值必须是有效的数字"
      };
    }
    return { isValid: true };
  }
  return {
    isValid: false,
    error: "默认值必须是有效的数字"
  };
};
var validateBoolean = (value) => {
  if (value === null || value === void 0 || value === "") {
    return { isValid: true };
  }
  if (typeof value === "string") {
    const trimmed = value.trim().toLowerCase();
    if (trimmed === "") {
      return { isValid: true };
    }
    if (trimmed !== "true" && trimmed !== "false") {
      return {
        isValid: false,
        error: "默认值必须是 true 或 false"
      };
    }
    return { isValid: true };
  }
  if (typeof value === "boolean") {
    return { isValid: true };
  }
  return {
    isValid: false,
    error: "默认值必须是 true 或 false"
  };
};
var validateArray = (value) => {
  if (value === null || value === void 0 || value === "") {
    return { isValid: true };
  }
  if (typeof value === "string") {
    const trimmed = value.trim();
    if (trimmed === "") {
      return { isValid: true };
    }
    try {
      const parsed = JSON.parse(trimmed);
      if (typeof parsed !== "object" || parsed === null) {
        return {
          isValid: false,
          error: "默认值必须是有效的JSON对象或数组"
        };
      }
      return { isValid: true };
    } catch (error) {
      return {
        isValid: false,
        error: "默认值必须是有效的JSON对象或数组"
      };
    }
  }
  if (typeof value === "object" && value !== null) {
    return { isValid: true };
  }
  return {
    isValid: false,
    error: "默认值必须是有效的JSON对象或数组"
  };
};
var validateDefaultValue = (fieldType, defaultValue) => {
  if (!fieldType) {
    return {
      isValid: false,
      error: "字段类型不能为空"
    };
  }
  switch (fieldType.toLowerCase()) {
    case "string":
      return validateString(defaultValue);
    case "integer":
      return validateInteger(defaultValue);
    case "float":
      return validateFloat(defaultValue);
    case "boolean":
      return validateBoolean(defaultValue);
    case "array":
      return validateArray(defaultValue);
    default:
      return {
        isValid: false,
        error: `不支持的字段类型: ${fieldType}`
      };
  }
};
var parseDefaultValue = (fieldType, defaultValue) => {
  if (defaultValue === null || defaultValue === void 0 || defaultValue === "") {
    return null;
  }
  switch (fieldType.toLowerCase()) {
    case "string":
      return String(defaultValue);
    case "integer":
      if (typeof defaultValue === "string") {
        const trimmed = defaultValue.trim();
        if (trimmed === "") return null;
        return parseInt(trimmed, 10);
      }
      return defaultValue;
    case "float":
      if (typeof defaultValue === "string") {
        const trimmed = defaultValue.trim();
        if (trimmed === "") return null;
        return parseFloat(trimmed);
      }
      return defaultValue;
    case "boolean":
      if (typeof defaultValue === "string") {
        const trimmed = defaultValue.trim().toLowerCase();
        if (trimmed === "") return null;
        return trimmed === "true";
      }
      return Boolean(defaultValue);
    case "array":
      if (typeof defaultValue === "string") {
        const trimmed = defaultValue.trim();
        if (trimmed === "") return null;
        return JSON.parse(trimmed);
      }
      return defaultValue;
    default:
      return defaultValue;
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  parseDefaultValue,
  validateDefaultValue
});
