/// Tests unitaires pour DeleteEvent use case
library delete_event_test;

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/features/events/domain/repositories/evenement_repository.dart';
import 'package:unionflow_mobile_apps/features/events/domain/usecases/delete_event.dart';

@GenerateMocks([IEvenementRepository])
import 'delete_event_test.mocks.dart';

void main() {
  late DeleteEvent useCase;
  late MockIEvenementRepository mockRepository;

  setUp(() {
    mockRepository = MockIEvenementRepository();
    useCase = DeleteEvent(mockRepository);
  });

  group('DeleteEvent Use Case', () {
    const tEventId = 'event123';

    test('should delete event successfully', () async {
      // Arrange
      when(mockRepository.deleteEvenement(tEventId))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(tEventId);

      // Assert
      verify(mockRepository.deleteEvenement(tEventId));
      verifyNoMoreInteractions(mockRepository);
    });

    test('should throw exception when event not found', () async {
      // Arrange
      when(mockRepository.deleteEvenement(any))
          .thenThrow(Exception('Événement non trouvé'));

      // Act & Assert
      expect(() => useCase('nonexistent'), throwsA(isA<Exception>()));
      verify(mockRepository.deleteEvenement('nonexistent'));
    });

    test('should throw exception when event has participants', () async {
      // Arrange
      when(mockRepository.deleteEvenement(any))
          .thenThrow(Exception('Impossible de supprimer un événement avec des participants'));

      // Act & Assert
      expect(() => useCase(tEventId), throwsA(isA<Exception>()));
    });

    test('should throw exception when deletion fails', () async {
      // Arrange
      when(mockRepository.deleteEvenement(any))
          .thenThrow(Exception('Erreur de suppression'));

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