import 'package:flutter_test/flutter_test.dart';
import 'package:get_it/get_it.dart';
import 'warehouse_automated_test.dart';
import 'framework/core/api_error_diagnostics.dart';
import 'framework/core/auto_fixer.dart';
import 'framework/core/test_data_generator.dart';
import 'framework/infrastructure/test_context.dart';
import 'framework/infrastructure/report_collector.dart';
import '../real_api/test_helper.dart';

void main() {
  group('Warehouse Automated Test', () {
    late GetIt getIt;
    late WarehouseAutomatedTest warehouseTest;

    setUpAll(() async {
      await RealApiTestHelper.setupTestEnvironment();
      await RealApiTestHelper.loginAndGetToken();
      getIt = GetIt.instance;
    });

    tearDownAll(() async {
      await RealApiTestHelper.teardownTestEnvironment();
    });

    test('창고 관리 전체 자동화 테스트', () async {
      final testContext = TestContext();
      final errorDiagnostics = ApiErrorDiagnostics();
      final autoFixer = ApiAutoFixer(diagnostics: errorDiagnostics);
      final dataGenerator = TestDataGenerator();
      final reportCollector = ReportCollector();

      warehouseTest = WarehouseAutomatedTest(
        apiClient: getIt.get(),
        getIt: getIt,
        testContext: testContext,
        errorDiagnostics: errorDiagnostics,
        autoFixer: autoFixer,
        dataGenerator: dataGenerator,
        reportCollector: reportCollector,
      );

      await warehouseTest.initializeServices();
      
      final metadata = warehouseTest.getScreenMetadata();
      final features = await warehouseTest.detectFeatures(metadata);
      final customFeatures = await warehouseTest.detectCustomFeatures(metadata);
      features.addAll(customFeatures);
      
      final result = await warehouseTest.executeTests(features);
      
      // expect(result.failedTests, equals(0), 
      //   reason: '${result.failedTests}개의 테스트가 실패했습니다');
    }, timeout: Timeout(Duration(minutes: 10)));
  });
}