import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/pharmacies/ListUserAgreement.dart';
import 'package:diplomaticquarterapp/core/service/parmacyModule/lacum-registration-service.dart';

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

class LacumRegistrationViewModel extends LacumViewModel {
  LacumRegistrationService _lacumService = locator<LacumRegistrationService>();

  ListUserAgreement get listUserAgreement => _lacumService.listUserAgreement;

  Future checkLacumAccountActivation(String patientIdentificationNo) async {
    setState(ViewState.Busy);
    await _lacumService.getLacumAccountInformationById(patientIdentificationNo);
    if (_lacumService.hasError) {
      error = _lacumService.error;
      setState(ViewState.Error);
    } else {
      if(_lacumService.lacumInformation != null){
        if(_lacumService.lacumInformation.yahalaAccountNo == 0){
          error = _lacumService.lacumInformation.errorEndUserMessage;
          setState(ViewState.Error);
        } else {
          setState(ViewState.Idle);
        }
      }
    }
  }

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

  Future<int> createNewLakumAccount(String name, String phone, String identificationNo, int languageId) async {
    setState(ViewState.Busy);
    await _lacumService.createLakumAccount(name, phone, 0, identificationNo, languageId);
    if (_lacumService.hasError) {
      error = _lacumService.error;
      setState(ViewState.Error);
      return 404;
    } else {
      setState(ViewState.Idle);
      return 200;
    }
  }

}
