import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/model/procedure/categories_procedure.dart';
import 'package:doctor_app_flutter/core/model/procedure/get_procedure_model.dart';
import 'package:doctor_app_flutter/core/model/procedure/post_procedure_req_model.dart';
import 'package:doctor_app_flutter/core/service/procedure_service.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/locator.dart';

class ProcedureViewModel extends BaseViewModel {
  bool hasError = false;
  ProcedureService _procedureService = locator<ProcedureService>();
  List<GetProcedureModel> get procedureList => _procedureService.procedureList;
  List<CategoriseProcedureModel> get categoriesList =>
      _procedureService.categoriesList;

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

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

  Future postProcedure(PostProcedureReqModel postProcedureReqModel) async {
    hasError = false;
    //_insuranceCardService.clearInsuranceCard();
    setState(ViewState.Busy);
    await _procedureService.postProcedure(postProcedureReqModel);
    if (_procedureService.hasError) {
      error = _procedureService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
