import 'package:hmg_patient_app/core/enum/viewstate.dart';
import 'package:hmg_patient_app/core/model/pharmacy/offer_products_model.dart';
import 'package:hmg_patient_app/core/model/pharmacy/offers_model.dart';
import 'package:hmg_patient_app/core/service/offers_service.dart';
import 'package:hmg_patient_app/locator.dart';

import 'base_view_model.dart';

class OffersCategoriseViewModel extends BaseViewModel {
  bool hasError = false;

  OffersCategoriseService _offersCategoriseService =
      locator<OffersCategoriseService>();
  List<OffersModel> get categorise => _offersCategoriseService.offersList;

  List<OfferProductsModel> get products =>
      _offersCategoriseService.offersProducts;

  Future getOffersCategorise() async {
    hasError = false;
    _offersCategoriseService.clearCategorise();
    setState(ViewState.Busy);
    await _offersCategoriseService.getOffersCategorise();
    if (_offersCategoriseService.hasError) {
      error = _offersCategoriseService.error!;
      setState(ViewState.ErrorLocal);
    } else
      await getOffersProducts();
  }

  Future getOffersProducts({String? i}) async {
    hasError = false;

    setState(ViewState.Busy);
    await _offersCategoriseService.getOffersProducts(id: i!);
    if (_offersCategoriseService.hasError) {
      error = _offersCategoriseService.error!;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
// await _offersCategoriseService.getOffersProducts();
// if (_offersCategoriseService.hasError) {
// error = _offersCategoriseService.error;
// setState(ViewState.ErrorLocal);
// } else
// setState(ViewState.Idle);
