import 'package:local_auth/local_auth.dart';

import 'logger_service.dart';

class LocalAuthService {
  final LocalAuthentication localAuth;
  final LoggerService loggerService;
  LocalAuthService({required this.localAuth, required this.loggerService});
  Future<bool> authenticate() async {
    try {
      final canCheck = await localAuth.canCheckBiometrics;
      final isDeviceSupported = await localAuth.isDeviceSupported();

      if (!canCheck || !isDeviceSupported) {
        return false;
      }

      final isAuthenticated = await localAuth.authenticate(
        localizedReason: 'Please authenticate to proceed',
        options: const AuthenticationOptions(
          biometricOnly: true,
          stickyAuth: true,
        ),
      );

      return isAuthenticated;
    } catch (e) {
     print(e);
      return false;
    }
  }


  Future<bool> canCheckBiometrics() async {
    try {
      return await localAuth.canCheckBiometrics;
    } catch (e) {
      return false;
    }
  }

  Future<List<BiometricType>> getAvailableBiometrics() async {
    try {
      return await localAuth.getAvailableBiometrics();
    } catch (e) {
      return [];
    }
  }
}