/// Tests unitaires pour RegisterForEvent use case
library register_for_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/register_for_event.dart';

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

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

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

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

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

      // Act
      await useCase(tEventId);

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

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

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

    test('should throw exception when already registered', () async {
      // Arrange
      when(mockRepository.inscrireEvenement(any))
          .thenThrow(Exception('Vous êtes déjà inscrit à cet événement'));

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

    test('should throw exception when event is full', () async {
      // Arrange
      when(mockRepository.inscrireEvenement(any))
          .thenThrow(Exception('Événement complet'));

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