import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart';
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/service/SOAP_service.dart';
import 'package:doctor_app_flutter/models/SOAP/Allergy_model.dart';
import 'package:doctor_app_flutter/models/SOAP/get_Allergies_request_model.dart';
import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart';
import 'package:doctor_app_flutter/models/SOAP/post_allergy_request_model.dart';
import 'package:doctor_app_flutter/models/SOAP/post_chief_complaint_request_model.dart';
import 'package:doctor_app_flutter/models/SOAP/post_histories_request_model.dart';

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

class SOAPViewModel extends BaseViewModel {
  SOAPService _SOAPService = locator<SOAPService>();

  List<MasterKeyModel> get listOfAllergies => _SOAPService.listOfAllergies;

  List<MasterKeyModel> get allergySeverityList =>
      _SOAPService.allergySeverityList;


  List<MasterKeyModel> get historyFamilyList => _SOAPService.historyFamilyList;

  List<MasterKeyModel> get historyMedicalList => _SOAPService.historyMedicalList;

  List<MasterKeyModel> get historySportList => _SOAPService.historySportList;

  List<MasterKeyModel> get historySocialList => _SOAPService.historySocialList;
  List<MasterKeyModel> get historySurgicalList => _SOAPService.historySurgicalList;
  List<MasterKeyModel> get mergeHistorySurgicalWithHistorySportList => [...historySurgicalList,...historySportList];
  List<MasterKeyModel> get  physicalExaminationList => _SOAPService.physicalExaminationList;



  Future getAllergies(GetAllergiesRequestModel getAllergiesRequestModel) async {
    setState(ViewState.Busy);
    await _SOAPService.getAllergies(getAllergiesRequestModel);
    if (_SOAPService.hasError) {
      error = _SOAPService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future getMasterLookup(MasterKeysService masterKeys) async {
    setState(ViewState.Busy);
    await _SOAPService.getMasterLookup(masterKeys);
    if (_SOAPService.hasError) {
      error = _SOAPService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future postAllergy(PostAllergyRequestModel postAllergyRequestModel) async {
    setState(ViewState.BusyLocal);
    await _SOAPService.postAllergy(postAllergyRequestModel);
    if (_SOAPService.hasError) {
      error = _SOAPService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }

  Future postHistories(PostHistoriesRequestModel postHistoriesRequestModel) async {
    setState(ViewState.BusyLocal);
    await _SOAPService.postHistories(postHistoriesRequestModel);
    if (_SOAPService.hasError) {
      error = _SOAPService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }

  Future postChiefComplaint(PostChiefComplaintRequestModel postChiefComplaintRequestModel) async {
    setState(ViewState.BusyLocal);
    await _SOAPService.postChiefComplaint(postChiefComplaintRequestModel);
    if (_SOAPService.hasError) {
      error = _SOAPService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }


}
