/// Tests unitaires pour DeleteAccount use case
library delete_account_test;

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart';
import 'package:unionflow_mobile_apps/features/profile/domain/usecases/delete_account.dart';

@GenerateMocks([IProfileRepository])
import 'delete_account_test.mocks.dart';

void main() {
  late DeleteAccount useCase;
  late MockIProfileRepository mockRepository;

  setUp(() {
    mockRepository = MockIProfileRepository();
    useCase = DeleteAccount(mockRepository);
  });

  group('DeleteAccount Use Case', () {
    const tMembreId = 'membre1';

    test('should delete account successfully (soft delete)', () async {
      // Arrange
      when(mockRepository.deleteAccount(tMembreId))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(tMembreId);

      // Assert
      verify(mockRepository.deleteAccount(tMembreId));
      verifyNoMoreInteractions(mockRepository);
    });

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

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

    test('should throw exception when account is already deleted', () async {
      // Arrange
      when(mockRepository.deleteAccount(any))
          .thenThrow(Exception('Compte déjà désactivé'));

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

    test('should throw exception when deletion fails', () async {
      // Arrange
      when(mockRepository.deleteAccount(any))
          .thenThrow(Exception('Deletion failed'));

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