function isPlainObject(item) {
  return item !== null && typeof item === "object" && !Array.isArray(item) && !(item instanceof Date) && !(item instanceof RegExp) && !(item instanceof Map) && !(item instanceof Set);
}
function deepMerge(target, source) {
  const output = { ...target };
  if (!isPlainObject(target) || !isPlainObject(source)) {
    return source;
  }
  Object.keys(source).forEach((key) => {
    const sourceValue = source[key];
    const targetValue = target[key];
    if (sourceValue === void 0) {
      return;
    }
    if (sourceValue === null) {
      output[key] = null;
      return;
    }
    if (isPlainObject(targetValue) && isPlainObject(sourceValue)) {
      output[key] = deepMerge(targetValue, sourceValue);
      return;
    }
    output[key] = sourceValue;
  });
  return output;
}
function mergeConfigs(...configs) {
  const validConfigs = configs.filter(
    (config) => config != null
  );
  if (validConfigs.length === 0) {
    throw new Error("At least one valid config must be provided");
  }
  let result = validConfigs[0];
  for (let i = 1; i < validConfigs.length; i++) {
    result = deepMerge(result, validConfigs[i]);
  }
  return result;
}
function validateRequiredProperties(merged, required) {
  const missing = [];
  for (const path of required) {
    const parts = path.split(".");
    let current = merged;
    for (const part of parts) {
      if (current == null || !(part in current)) {
        missing.push(path);
        break;
      }
      current = current[part];
    }
  }
  if (missing.length > 0) {
    throw new Error(
      `Configuration validation failed. Missing required properties:
${missing.join("\n")}`
    );
  }
}
function getConfigProperty(config, path, defaultValue) {
  const parts = path.split(".");
  let current = config;
  for (const part of parts) {
    if (current == null || !(part in current)) {
      return defaultValue;
    }
    current = current[part];
  }
  return current;
}
function setConfigProperty(config, path, value) {
  const parts = path.split(".");
  const lastPart = parts.pop();
  let current = config;
  for (const part of parts) {
    if (!(part in current) || !isPlainObject(current[part])) {
      current[part] = {};
    }
    current = current[part];
  }
  current[lastPart] = value;
}
export {
  deepMerge,
  getConfigProperty,
  mergeConfigs,
  setConfigProperty,
  validateRequiredProperties
};
