import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/features/habib_wallet/habib_wallet_repo.dart';
import 'package:hmg_patient_app_new/services/error_handler_service.dart';

class HabibWalletViewModel extends ChangeNotifier {
  bool isWalletAmountLoading = false;
  num habibWalletAmount = 0;

  HabibWalletRepo habibWalletRepo;
  ErrorHandlerService errorHandlerService;

  HabibWalletViewModel({required this.habibWalletRepo, required this.errorHandlerService});

  initHabibWalletProvider() {
    isWalletAmountLoading = true;
    habibWalletAmount = 0;
    notifyListeners();
  }

  Future<void> getPatientBalanceAmount({Function(dynamic)? onSuccess, Function(String)? onError}) async {
    final result = await habibWalletRepo.getPatientBalanceAmount();

    result.fold(
      (failure) async => await errorHandlerService.handleError(failure: failure),
      (apiResponse) {
        if (apiResponse.messageStatus == 2) {
          // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {});
        } else if (apiResponse.messageStatus == 1) {
          habibWalletAmount = apiResponse.data!;
          isWalletAmountLoading = false;
          notifyListeners();
          if (onSuccess != null) {
            onSuccess(apiResponse);
          }
        }
      },
    );
  }
}
