import 'package:flutter_test/flutter_test.dart';
import 'package:rmtpocketwatcher/services/update_service.dart';

void main() {
  group('UpdateService', () {
    late UpdateService updateService;

    setUp(() {
      updateService = UpdateService();
    });

    test('version extraction works correctly', () {
      // Test version extraction
      expect(updateService.extractVersionFromTag('v1.2.3'), equals('1.2.3'));
      expect(updateService.extractVersionFromTag('1.2.3'), equals('1.2.3'));
      expect(updateService.extractVersionFromTag('v2.0.0'), equals('2.0.0'));
    });

    test('newer version detection works correctly', () {
      expect(updateService.isNewerVersion('1.2.4', '1.2.3'), isTrue);
      expect(updateService.isNewerVersion('1.3.0', '1.2.9'), isTrue);
      expect(updateService.isNewerVersion('2.0.0', '1.9.9'), isTrue);
      expect(updateService.isNewerVersion('1.2.3', '1.2.3'), isFalse);
      expect(updateService.isNewerVersion('1.2.2', '1.2.3'), isFalse);
      expect(updateService.isNewerVersion('1.1.9', '1.2.0'), isFalse);
    });

    test('platform asset detection works', () {
      final assets = [
        ReleaseAsset(
          name: 'rmtPocketWatcher-windows-x64.exe',
          downloadUrl: 'https://example.com/windows.exe',
          size: 1024,
          contentType: 'application/octet-stream',
        ),
        ReleaseAsset(
          name: 'rmtPocketWatcher-macos.dmg',
          downloadUrl: 'https://example.com/macos.dmg',
          size: 2048,
          contentType: 'application/octet-stream',
        ),
        ReleaseAsset(
          name: 'rmtPocketWatcher-linux.appimage',
          downloadUrl: 'https://example.com/linux.appimage',
          size: 3072,
          contentType: 'application/octet-stream',
        ),
      ];

      final updateInfo = UpdateInfo(
        currentVersion: '1.0.0',
        latestVersion: '1.1.0',
        releaseUrl: 'https://example.com/release',
        releaseName: 'Test Release',
        releaseNotes: 'Test notes',
        publishedAt: DateTime.now(),
        assets: assets,
      );

      // This test would need to mock the platform detection
      // For now, just verify the asset list is properly structured
      expect(updateInfo.assets.length, equals(3));
      expect(updateInfo.assets.first.name, contains('windows'));
    });
  });
}

// Note: The methods extractVersionFromTag and isNewerVersion are now public
// and marked with @visibleForTesting for testing purposes