import 'package:flutter_test/flutter_test.dart';
import 'package:recording_tool/core/platform/device_health_checker.dart';
import 'package:recording_tool/core/platform/device_health_snapshot.dart';

void main() {
  group('DeviceHealthChecker.warningLines', () {
    test('returns empty when battery and storage are healthy', () {
      const snapshot = DeviceHealthSnapshot(
        batteryLevelPercent: 50,
        storageAvailablePercent: 50,
      );

      expect(DeviceHealthChecker.warningLines(snapshot), isEmpty);
    });

    test('returns low battery message only', () {
      const snapshot = DeviceHealthSnapshot(
        batteryLevelPercent: 9,
        storageAvailablePercent: 50,
      );

      expect(
        DeviceHealthChecker.warningLines(snapshot),
        [DeviceHealthChecker.lowBatteryMessage],
      );
    });

    test('returns low storage message only', () {
      const snapshot = DeviceHealthSnapshot(
        batteryLevelPercent: 50,
        storageAvailablePercent: 9.9,
      );

      expect(
        DeviceHealthChecker.warningLines(snapshot),
        [DeviceHealthChecker.lowStorageMessage],
      );
    });

    test('returns both messages when battery and storage are low', () {
      const snapshot = DeviceHealthSnapshot(
        batteryLevelPercent: 5,
        storageAvailablePercent: 5,
      );

      expect(
        DeviceHealthChecker.warningLines(snapshot),
        [
          DeviceHealthChecker.lowBatteryMessage,
          DeviceHealthChecker.lowStorageMessage,
        ],
      );
    });

    test('does not warn at exactly threshold percent', () {
      const snapshot = DeviceHealthSnapshot(
        batteryLevelPercent: 10,
        storageAvailablePercent: 10,
      );

      expect(DeviceHealthChecker.warningLines(snapshot), isEmpty);
    });

    test('skips battery warning when level is unknown', () {
      const snapshot = DeviceHealthSnapshot(
        batteryLevelPercent: null,
        storageAvailablePercent: 5,
      );

      expect(
        DeviceHealthChecker.warningLines(snapshot),
        [DeviceHealthChecker.lowStorageMessage],
      );
    });
  });

  group('DeviceHealthSnapshot.fromMap', () {
    test('parses native map fields', () {
      final snapshot = DeviceHealthSnapshot.fromMap({
        'batteryLevelPercent': 42,
        'storageAvailablePercent': 12.5,
      });

      expect(snapshot.batteryLevelPercent, 42);
      expect(snapshot.storageAvailablePercent, 12.5);
    });
  });
}
