import 'package:flutter/material.dart';

import 'package:pweb/services/auth.dart';


class TwoFactorProvider extends ChangeNotifier {
  final AuthenticationService _authService;

  TwoFactorProvider(this._authService);

  bool _isSubmitting = false;
  bool _hasError = false;
  bool _verificationSuccess = false;

  bool get isSubmitting => _isSubmitting;
  bool get hasError => _hasError;
  bool get verificationSuccess => _verificationSuccess;


  Future<void> submitCode(String code) async {
    _isSubmitting = true;
    _hasError = false;
    _verificationSuccess = false;
    notifyListeners(); 

    try {
      final success = await _authService.verifyTwoFactorCode(code);
      if (success) {
        _verificationSuccess = true;
      }
    } catch (e) {
      _hasError = true;
    } finally {
      _isSubmitting = false;
      notifyListeners();
    }
  }
}