function getEnvConfig(config) {
  const env = process.env.NODE_ENV || "development";
  return config.environments[env] || config.environments.development;
}
function isDevelopment() {
  return process.env.NODE_ENV === "development";
}
function isProduction() {
  return process.env.NODE_ENV === "production";
}
function validateI18nConfig(config) {
  const errors = [];
  if (!config.supportedLocales.length) {
    errors.push("At least one supported locale must be configured");
  }
  if (!config.supportedLocales.includes(config.defaultLocale)) {
    errors.push("Default locale must be included in supported locales");
  }
  if (!config.namespaces.length) {
    errors.push("At least one translation namespace must be configured");
  }
  if (!config.detectionStrategy.length) {
    errors.push("At least one detection strategy must be configured");
  }
  return {
    valid: errors.length === 0,
    errors
  };
}
function validateApplicationConfig(config) {
  var _a, _b, _c, _d;
  const errors = [];
  const i18nValidation = validateI18nConfig(config.i18n);
  if (!i18nValidation.valid) {
    errors.push(...i18nValidation.errors.map((error) => `I18n: ${error}`));
  }
  if (!((_a = config.app.name) == null ? void 0 : _a.trim())) {
    errors.push("App: name is required");
  }
  if (!((_b = config.app.version) == null ? void 0 : _b.trim())) {
    errors.push("App: version is required");
  }
  if (!((_d = (_c = config.app.contact) == null ? void 0 : _c.email) == null ? void 0 : _d.trim())) {
    errors.push("App: contact email is required");
  }
  if (!config.userRoles.availableRoles.length) {
    errors.push("UserRoles: at least one role must be available");
  }
  if (!config.userRoles.availableRoles.includes(config.userRoles.defaultRole)) {
    errors.push("UserRoles: defaultRole must be included in availableRoles");
  }
  return {
    valid: errors.length === 0,
    errors
  };
}
function getAllowedCorsOrigins(config) {
  const env = process.env.NODE_ENV || "development";
  return config.api.cors.allowedOrigins[env] || [];
}
function isCorsAllowAllOrigins(config) {
  const env = process.env.NODE_ENV || "development";
  return config.api.cors.allowAllOrigins[env] || false;
}
function getRoleHierarchy(config, role) {
  return config.userRoles.hierarchy[role] ?? 999;
}
function hasRolePermission(config, userRole, requiredRole) {
  const userLevel = getRoleHierarchy(config, userRole);
  const requiredLevel = getRoleHierarchy(config, requiredRole);
  return userLevel <= requiredLevel;
}
function getFeatureFlag(config, featureName) {
  return config.features[featureName] ?? false;
}
function debugConfig(config) {
  if (!isDevelopment()) return;
  const validation = validateApplicationConfig(config);
  console.group("\u{1F527} Application Configuration Debug");
  console.log("Valid:", validation.valid);
  if (!validation.valid) {
    console.error("Validation Errors:", validation.errors);
  }
  console.log("Environment:", process.env.NODE_ENV);
  console.log("App Name:", config.app.name);
  console.log("Supported Locales:", config.i18n.supportedLocales);
  console.log("Available Roles:", config.userRoles.availableRoles);
  console.log("Feature Flags:", config.features);
  console.groupEnd();
}
export {
  debugConfig,
  getAllowedCorsOrigins,
  getEnvConfig,
  getFeatureFlag,
  getRoleHierarchy,
  hasRolePermission,
  isCorsAllowAllOrigins,
  isDevelopment,
  isProduction,
  validateApplicationConfig,
  validateI18nConfig
};
