import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart';
import 'package:get_it/get_it.dart';
import 'package:superport/injection_container.dart' as di;
import 'package:superport/data/datasources/remote/dashboard_remote_datasource.dart';
import 'package:superport/data/datasources/remote/lookup_remote_datasource.dart';
import 'package:superport/core/services/lookups_service.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  setUpAll(() async {
    TestWidgetsFlutterBinding.ensureInitialized();
    SharedPreferences.setMockInitialValues({});
    await di.init();
  });

  tearDownAll(() {
    GetIt.instance.reset();
  });

  group('New API Integration Tests', () {
    test('DashboardRemoteDataSource should have getLicenseExpirySummary method', () {
      final dataSource = GetIt.instance<DashboardRemoteDataSource>();
      expect(dataSource, isNotNull);
      
      // 메서드가 존재하는지 확인
      expect(dataSource.getLicenseExpirySummary, isA<Function>());
    });

    test('LookupRemoteDataSource should be registered', () {
      final dataSource = GetIt.instance<LookupRemoteDataSource>();
      expect(dataSource, isNotNull);
      
      // 메서드들이 존재하는지 확인
      expect(dataSource.getAllLookups, isA<Function>());
      expect(dataSource.getLookupsByType, isA<Function>());
    });

    test('LookupsService should be registered', () {
      final service = GetIt.instance<LookupsService>();
      expect(service, isNotNull);
      
      // 프로퍼티와 메서드 확인
      expect(service.isInitialized, isFalse); // 초기 상태
      expect(service.initialize, isA<Function>());
    });

    test('License expiry summary API endpoint should be callable', () async {
      final dataSource = GetIt.instance<DashboardRemoteDataSource>();
      
      // API 호출 (실제 네트워크 호출이므로 실패할 수 있음)
      final result = await dataSource.getLicenseExpirySummary();
      
      // Either 타입 확인
      expect(result.isLeft() || result.isRight(), isTrue);
    });

    test('Lookups API endpoint should be callable', () async {
      final dataSource = GetIt.instance<LookupRemoteDataSource>();
      
      // API 호출 (실제 네트워크 호출이므로 실패할 수 있음)
      final result = await dataSource.getAllLookups();
      
      // Either 타입 확인
      expect(result.isLeft() || result.isRight(), isTrue);
    });
  });
}
