import 'package:hmg_patient_app/core/enum/viewstate.dart';
import 'package:hmg_patient_app/core/model/prescriptions/Prescriptions.dart';
import 'package:hmg_patient_app/core/service/parmacyModule/prescription_service.dart';
import 'package:hmg_patient_app/core/viewModels/base_view_model.dart';

import '../../../locator.dart';

class PrescriptionViewModel extends BaseViewModel {

  PrescriptionService _prescriptionService = locator<PrescriptionService>();

  List<Prescriptions> get prescriptionsList =>
      _prescriptionService.prescriptionsList;

  getPrescription() async {
    await getSavedLanguage();
    prescriptionsList.clear();
    if(prescriptionsList.isEmpty){
      setState(ViewState.Busy);
      await _prescriptionService.getPrescription();
      if (_prescriptionService.hasError) {
        error = _prescriptionService.error!;
        setState(ViewState.Error);
      } else {
        setState(ViewState.Idle);
      }
    }
  }
}