import 'package:diplomaticquarterapp/core/model/insurance/insurance_approval.dart';
import 'package:diplomaticquarterapp/core/model/insurance/insurance_card_update.dart';
import 'package:diplomaticquarterapp/pages/insurance/insurance_approval_screen.dart';

import 'base_view_model.dart';
import '../../locator.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/insurance/insurance_card.dart';
import 'package:diplomaticquarterapp/core/service/insurance_service.dart';

class InsuranceViewModel extends BaseViewModel {
  bool hasError = false;

  InsuranceCardService _insuranceCardService = locator<InsuranceCardService>();

  List<InsuranceCardModel> get insurance => _insuranceCardService.cardList;
  List<InsuranceUpdateModel> get insuranceUpdate =>
      _insuranceCardService.updatedCard;
  List<InsuranceApprovalModel> get insuranceApproval =>
      _insuranceCardService.insuranceApproval;

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

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

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