/// Tests unitaires pour DeleteMember use case
library delete_member_test;

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/features/members/domain/repositories/membre_repository.dart';
import 'package:unionflow_mobile_apps/features/members/domain/usecases/delete_member.dart';

@GenerateMocks([IMembreRepository])
import 'delete_member_test.mocks.dart';

void main() {
  late DeleteMember useCase;
  late MockIMembreRepository mockRepository;

  setUp(() {
    mockRepository = MockIMembreRepository();
    useCase = DeleteMember(mockRepository);
  });

  group('DeleteMember Use Case', () {
    const tMemberId = '123';

    test('should delete member successfully', () async {
      // Arrange
      when(mockRepository.deleteMembre(tMemberId))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(tMemberId);

      // Assert
      verify(mockRepository.deleteMembre(tMemberId));
      verifyNoMoreInteractions(mockRepository);
    });

    test('should delete member with confirmation', () async {
      // Arrange
      when(mockRepository.deleteMembre(tMemberId))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(tMemberId);

      // Assert
      verify(mockRepository.deleteMembre(tMemberId)).called(1);
    });

    test('should throw exception when member not found', () async {
      // Arrange
      when(mockRepository.deleteMembre(any))
          .thenThrow(Exception('Membre non trouvé'));

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

    test('should throw exception when member has dependencies', () async {
      // Arrange
      when(mockRepository.deleteMembre(any))
          .thenThrow(Exception('Impossible de supprimer: membre a des contributions actives'));

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