/// Tests unitaires pour DeleteOrganization use case
library delete_organization_test;

import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/features/organizations/domain/repositories/organization_repository.dart';
import 'package:unionflow_mobile_apps/features/organizations/domain/usecases/delete_organization.dart';

@GenerateMocks([IOrganizationRepository])
import 'delete_organization_test.mocks.dart';

void main() {
  late DeleteOrganization useCase;
  late MockIOrganizationRepository mockRepository;

  setUp(() {
    mockRepository = MockIOrganizationRepository();
    useCase = DeleteOrganization(mockRepository);
  });

  group('DeleteOrganization Use Case', () {
    const tOrganizationId = 'org1';

    test('should delete organization successfully', () async {
      // Arrange
      when(mockRepository.deleteOrganization(tOrganizationId))
          .thenAnswer((_) async => Future.value());

      // Act
      await useCase(tOrganizationId);

      // Assert
      verify(mockRepository.deleteOrganization(tOrganizationId));
      verifyNoMoreInteractions(mockRepository);
    });

    test('should throw exception when organization not found', () async {
      // Arrange
      when(mockRepository.deleteOrganization(any))
          .thenThrow(Exception('Organisation non trouvée'));

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

    test('should throw exception when organization has members', () async {
      // Arrange
      when(mockRepository.deleteOrganization(any))
          .thenThrow(Exception('Organisation contient des membres'));

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

    test('should throw exception when deletion fails', () async {
      // Arrange
      when(mockRepository.deleteOrganization(any))
          .thenThrow(Exception('Suppression échouée'));

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