// Import necessary testing packages and mocktail
import 'package:comwell_key_app/authentication/authentication_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
import 'package:comwell_key_app/utils/seos_repository.dart';

class MockSeosRepository extends Mock implements SeosRepository {}
class MockAuthenticationRepository extends Mock implements AuthenticationRepository {}

void main() {
  // Declare the mocks
  late MockSeosRepository mockSeosRepository;

  // Setup function runs before every test
  setUp(() {
    // Initialize the mocks
    TestWidgetsFlutterBinding.ensureInitialized();
    mockSeosRepository = MockSeosRepository();
  });

  group('AuthenticationRepository - SeosRepository integration', () {
    test('isEndpointSetup returns true when endpoint is setup', () async {
      when(() => mockSeosRepository.isEndpointSetup()).thenAnswer((_) async => true);

      expect(await mockSeosRepository.isEndpointSetup(), isTrue);
    });

    test('isEndpointSetup returns false when endpoint is not setup', () async {
      when(() => mockSeosRepository.isEndpointSetup()).thenAnswer((_) async => false);

      expect(await mockSeosRepository.isEndpointSetup(), isFalse);
    });

    test('refreshKeys returns a list of MobileKeysKey on success', () async {
      when(() => mockSeosRepository.refreshKeys()).thenAnswer((_) async => [MobileKeysKey(active: true, credentialType: 1)]);

      final keys = await mockSeosRepository.refreshKeys();
      expect(keys, isNotNull);
      expect(keys, isA<List<MobileKeysKey>>());
      expect(keys.length, equals(1));
    });

    test('refreshKeys throws an exception on failure', () async {
      when(() => mockSeosRepository.refreshKeys()).thenThrow(Exception('Failed to list keys'));

      expect(mockSeosRepository.refreshKeys(), throwsA(isA<Exception>()));
    });
  });
}