import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/er/ErPatientShareModel.dart';
import 'package:diplomaticquarterapp/core/model/er/TriageQuestionsModel.dart';
import 'package:diplomaticquarterapp/core/model/hospitals/hospitals_model.dart';
import 'package:diplomaticquarterapp/core/service/er/EdOnlineServices.dart';
import 'package:diplomaticquarterapp/core/service/hospital_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';

import '../../../locator.dart';

class EdOnlineViewModel extends BaseViewModel {
  HospitalService _hospitalService = locator<HospitalService>();

  EdOnlineServices _edOnlineServices = locator<EdOnlineServices>();

  List<HospitalsModel> get hospitals => _hospitalService.hospitals;

  List<TriageQuestionsModel> get triageQuestionsModelList =>
      _edOnlineServices.triageQuestionsModelList;

  ErPatientShareModel get erPatientShareModel => _edOnlineServices.erPatientShareModel;

  Future getHospitals() async {
    if(_hospitalService.hospitals.isEmpty){
    setState(ViewState.Busy);
    await _hospitalService.getHospitals();
    if (_hospitalService.hasError) {
      error = _hospitalService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
    }
  }

  Future getQuestions() async {
    if(_edOnlineServices.triageQuestionsModelList.isEmpty){
    setState(ViewState.Busy);
    await _edOnlineServices.getQuestions();
    if (_edOnlineServices.hasError) {
      error = _edOnlineServices.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
    }
  }

  Future getPatientPaymentInformation({var id}) async {
    setState(ViewState.Busy);
    await _edOnlineServices.getPatientPaymentInformation();
    if (_edOnlineServices.hasError) {
      error = _edOnlineServices.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future saveQuestionsInformation(
      {String notes,
      String chiefComplaint,
      int projectId,
      DateTime selectedTime,
      List<TriageQuestionsModel> selectedQuestions}) async {
    setState(ViewState.BusyLocal);
    await _edOnlineServices.saveQuestionsInformation(
        notes: notes,
        projectId: projectId,
        chiefComplaint: chiefComplaint,
        selectedTime: selectedTime,
        selectedQuestions: selectedQuestions);
    if (_edOnlineServices.hasError) {
      error = _edOnlineServices.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
