import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/service/medicine_service.dart';

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

class MedicineViewModel extends BaseViewModel {
  MedicineService _medicineService = locator<MedicineService>();
  get pharmacyItemsList => _medicineService.pharmacyItemsList;
  get pharmaciesList => _medicineService.pharmaciesList;


  Future getMedicineItem(String itemName) async {
    setState(ViewState.Busy);
    await _medicineService.getMedicineItem(itemName);
    if (_medicineService.hasError) {
      error = _medicineService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future getPharmaciesList(int itemId) async {
    setState(ViewState.Busy);
    await _medicineService.getPharmaciesList(itemId);
    if (_medicineService.hasError) {
      error = _medicineService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }
}
