import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/pharmacy/categorise_parent_model.dart';
import 'package:diplomaticquarterapp/core/model/pharmacy/parent_products_model.dart';
import 'package:diplomaticquarterapp/core/model/pharmacy/pharmacy_categorise.dart';
import 'package:diplomaticquarterapp/core/service/pharmacy_categorise_service.dart';
import 'package:diplomaticquarterapp/locator.dart';

import 'base_view_model.dart';

class PharmacyCategoriseViewModel extends BaseViewModel {
  bool hasError = false;
  PharmacyCategoriseService _pharmacyCategoriseService =
      locator<PharmacyCategoriseService>();

  List<PharmacyCategorise> get categorise =>
      _pharmacyCategoriseService.categoriseList;

  List<CategoriseParentModel> get categoriseParent =>
      _pharmacyCategoriseService.parentCategoriseList;

  List<ParentProductsModel> get parentProducts =>
      _pharmacyCategoriseService.parentProductsList;

  Future getCategorise() async {
    hasError = false;
    // _insuranceCardService.clearInsuranceCard();
    setState(ViewState.Busy);
    await _pharmacyCategoriseService.getCategorise();
    if (_pharmacyCategoriseService.hasError) {
      error = _pharmacyCategoriseService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }

  Future getCategoriseParent({String i}) async {
    hasError = false;
    // _insuranceCardService.clearInsuranceCard();
    setState(ViewState.Busy);
    await _pharmacyCategoriseService.getCategoriseParent(id: i);
    if (_pharmacyCategoriseService.hasError) {
      error = _pharmacyCategoriseService.error;
      setState(ViewState.ErrorLocal);
    } else
      await getParentProducts();
  }

  Future getParentProducts() async {
    hasError = false;
    // _insuranceCardService.clearInsuranceCard();
    setState(ViewState.Busy);
    await _pharmacyCategoriseService.getParentProducts();
    if (_pharmacyCategoriseService.hasError) {
      error = _pharmacyCategoriseService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
