import 'billing_docs_module.dart';
import 'feature_module.dart';
import 'purchase_management_module.dart';
import 'sales_management_module.dart';
import 'sales_operations_module.dart';

class ModuleRegistry {
  ModuleRegistry._();

  static final ModuleRegistry instance = ModuleRegistry._();

  final List<FeatureModule> _modules = [
    BillingDocsModule(),
    SalesManagementModule(),
    SalesOperationsModule(),
    PurchaseManagementModule(),
  ];

  Iterable<FeatureModule> get modules => _modules;

  List<ModuleDashboardCard> get enabledCards => _modules.where((m) => m.isEnabled).expand((m) => m.dashboardCards).toList();

  bool supportsRoute(String route) => enabledCards.any((card) => card.route == route);

  ModuleDashboardCard? cardForRoute(String route) {
    for (final module in _modules) {
      if (!module.isEnabled) continue;
      final card = module.cardByRoute(route);
      if (card != null) {
        return card;
      }
    }
    return null;
  }
}
