initialize method

Future<void> initialize({
  1. bool force = false,
})

Initialize rules integration with direct dependency

Implementation

Future<void> initialize({bool force = false}) async {
  ObslyLogger.log('🔄 RulesIntegration.initialize() called (force: $force)');
  if (_isInitialized && !force) {
    ObslyLogger.log(
        '⚠️ RulesIntegration already initialized - current state: ${_isAvailable ? 'AVAILABLE' : 'NOT AVAILABLE'}');
    return;
  }

  try {
    ObslyLogger.log('🔧 Initializing RulesController directly...');

    // Initialize rules controller directly - no more soft dependencies!
    final rawController = await RulesController.initialize();

    // Use controller directly
    _rulesController = rawController;
    _isAvailable = _rulesController!.isActive;

    ObslyLogger.log(
        '🎯 RulesController initialized: ${_rulesController?.runtimeType ?? 'null'}');
    ObslyLogger.log('🔍 Is available: $_isAvailable');
    ObslyLogger.log('🔍 Is active: ${_rulesController?.isActive ?? false}');

    if (_isAvailable) {
      // Pass the controller to RulesManager for unified execution
      ObslyLogger.log('🔍 Passing controller to RulesManager...');
      RulesManager.instance.setRulesController(_rulesController);

      // Connect the SDK instance to the RulesController for integration
      ObslyLogger.log(
          '🔗 Connecting ObslySDK instance to RulesController...');
      _rulesController!.setObslySDK(ObslySDK.instance);

      ObslyLogger.log(
          '🎯 Rules Engine ACTIVATED - Events will be processed through rules');
      ObslyLogger.log('🔧 Rules Controller: ${_rulesController.runtimeType}');
      ObslyLogger.log(
          '✅ Auto-rule execution enabled for HTTP, UI, Navigation, and Lifecycle events');
      ObslyLogger.log('🔧 Runtime execution enabled: $_isExecutionEnabled');
    } else {
      ObslyLogger.log(
          '⚪ Rules Engine DISABLED - RulesController initialization failed');
    }
  } catch (e) {
    ObslyLogger.warn('⚠️ Rules integration failed to initialize: $e');
    _isAvailable = false;
  } finally {
    _isInitialized = true;
    ObslyLogger.log(
        '✅ RulesIntegration initialization complete - isAvailable: $_isAvailable');
  }
}