import '../detectors/window_manager_detector.dart';

/// Mock window manager detector for testing
/// 
/// Allows tests to override window manager detection behavior
class MockWindowManagerDetector {
  static WindowManager? _mockedWindowManager;
  static Map<String, String>? _mockedEnvironment;

  /// Set the window manager that should be detected in tests
  static void mockDetection(WindowManager windowManager) {
    _mockedWindowManager = windowManager;
  }

  /// Set mock environment variables for testing detection logic
  static void mockEnvironment(Map<String, String> environment) {
    _mockedEnvironment = environment;
  }

  /// Clear all mocks
  static void clearMocks() {
    _mockedWindowManager = null;
    _mockedEnvironment = null;
    // Reset the detector singleton
    WindowManagerDetector.instance.reset();
  }

  /// Get the currently mocked window manager
  static WindowManager? get mockedWindowManager => _mockedWindowManager;

  /// Get the currently mocked environment
  static Map<String, String>? get mockedEnvironment => _mockedEnvironment;

  /// Create a test scenario for Hyprland
  static void setupHyprlandTest() {
    mockEnvironment({
      'HYPRLAND_INSTANCE_SIGNATURE': 'test_signature_12345',
      'WAYLAND_DISPLAY': 'wayland-1',
      'XDG_CURRENT_DESKTOP': 'Hyprland',
      'XDG_SESSION_TYPE': 'wayland',
    });
    mockDetection(WindowManager.hyprland);
  }

  /// Create a test scenario for Sway
  static void setupSwayTest() {
    mockEnvironment({
      'SWAYSOCK': '/run/user/1000/sway-ipc.sock',
      'WAYLAND_DISPLAY': 'wayland-1',
      'XDG_CURRENT_DESKTOP': 'sway',
      'XDG_SESSION_TYPE': 'wayland',
    });
    mockDetection(WindowManager.sway);
  }

  /// Create a test scenario for unknown window manager
  static void setupUnknownTest() {
    mockEnvironment({
      'XDG_SESSION_TYPE': 'x11',
      'XDG_CURRENT_DESKTOP': 'GNOME',
    });
    mockDetection(WindowManager.unknown);
  }

  /// Verify detection results match expectations
  static bool verifyDetection(WindowManager expected) {
    return WindowManagerDetector.instance.detect() == expected;
  }

  /// Get detailed detection info for debugging tests
  static Map<String, dynamic> getTestDetectionInfo() {
    return {
      'mocked_window_manager': _mockedWindowManager?.toString(),
      'mocked_environment': _mockedEnvironment,
      'actual_detection': WindowManagerDetector.instance.detect().toString(),
      'actual_detection_info': WindowManagerDetector.instance.getDetectionInfo(),
    };
  }
}