import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/Prescription_model.dart';
import 'package:doctor_app_flutter/core/model/post_prescrition_req_model.dart';
import 'package:doctor_app_flutter/core/service/prescription_service.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/locator.dart';

class PrescriptionViewModel extends BaseViewModel {
  bool hasError = false;
  PrescriptionService _prescriptionService = locator<PrescriptionService>();

  List<PrescriptionModel> get prescriptionList =>
      _prescriptionService.prescriptionList;

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

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