/// Tests unitaires pour GenerateReport use case
library generate_report_test;

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/features/reports/domain/repositories/reports_repository.dart';
import 'package:unionflow_mobile_apps/features/reports/domain/usecases/generate_report.dart';

@GenerateMocks([IReportsRepository])
import 'generate_report_test.mocks.dart';

void main() {
  late GenerateReport useCase;
  late MockIReportsRepository mockRepository;

  setUp(() {
    mockRepository = MockIReportsRepository();
    useCase = GenerateReport(mockRepository);
  });

  group('GenerateReport Use Case', () {
    const tReportType = 'membres';
    const tFormat = 'pdf';

    test('should generate report successfully', () async {
      // Arrange
      when(mockRepository.generateReport(tReportType, format: null))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(tReportType);

      // Assert
      verify(mockRepository.generateReport(tReportType, format: null));
      verifyNoMoreInteractions(mockRepository);
    });

    test('should generate report with specific format', () async {
      // Arrange
      when(mockRepository.generateReport(tReportType, format: tFormat))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(tReportType, format: tFormat);

      // Assert
      verify(mockRepository.generateReport(tReportType, format: tFormat));
    });

    test('should generate report for different types', () async {
      // Arrange
      const altType = 'cotisations';
      when(mockRepository.generateReport(altType, format: null))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(altType);

      // Assert
      verify(mockRepository.generateReport(altType, format: null));
    });

    test('should throw exception when generation fails', () async {
      // Arrange
      when(mockRepository.generateReport(any, format: anyNamed('format')))
          .thenThrow(Exception('Generation failed'));

      // Act & Assert
      expect(() => useCase(tReportType), throwsException);
    });
  });
}
