import 'package:hmg_patient_app/core/enum/viewstate.dart';
import 'package:hmg_patient_app/core/model/pharmacies/LacumAccountInformation.dart';
import 'package:hmg_patient_app/core/service/parmacyModule/lacum-transfer-service.dart';

import '../../../locator.dart';
import 'lacum-viewmodel.dart';

class LacumTranferViewModel extends LacumViewModel {
  LacumTransferService _lacumService = locator<LacumTransferService>();

  LacumAccountInformation? get lacumReceiverInformation =>
      _lacumService.lacumReceiverInformation;

  Future getLacumGroupDataBuAccountId(String accountId) async {
    setState(ViewState.Busy);
    await _lacumService.getLacumGroupDataBuAccountId(accountId);
    if (_lacumService.hasError) {
      error = _lacumService.error!;
      setState(ViewState.Error);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future<int> transferYaHalaLoyaltyPoints(String points) async {
    setState(ViewState.Busy);
    await _lacumService.transferYaHalaLoyaltyPoints(points);
    if (_lacumService.hasError) {
      error = _lacumService.error!;
      setState(ViewState.Error);
      return 404;
    } else {
      setState(ViewState.Idle);
      return 200;
    }
  }

  setLakumData(LacumAccountInformation lacumInformation, LacumAccountInformation lacumGroupInformation){
    _lacumService.lacumInformation = lacumInformation;
    _lacumService.lacumGroupInformation = lacumGroupInformation;
  }
}
