import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart';
import 'package:doctor_app_flutter/models/SOAP/GetAssessmentResModel.dart';
import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart';
import 'package:flutter/cupertino.dart';

import 'base_service.dart';

class LookupService extends BaseService {
  List<MasterKeyModel> allergiesList = [];

  List<MasterKeyModel> get allergySeverityList => _allergySeverityList;
  List<MasterKeyModel> _allergySeverityList = [];

  List<dynamic> medicationStrengthList = [];
  List<dynamic> medicationDurationList = [];
  List<dynamic> medicationRouteList = [];
  List<dynamic> medicationFrequencyList = [];
  List<dynamic> medicationDoseTimeList = [];
  List<dynamic> medicationIndicationsList = [];
  // TODO make the person who create the list dynamic to change it.
  List<MasterKeyModel> medicationStrengthListWithModel = [];
  List<MasterKeyModel> medicationFrequencyListWithModel = [];
  List<MasterKeyModel> medicationDoseTimeListWithModel = [];
  List<MasterKeyModel> medicationRouteListWithModel = [];

  List<GetAssessmentResModel> patientAssessmentList = [];

  List<MasterKeyModel> get historyFamilyList => _historyFamilyList;
  List<MasterKeyModel> _historyFamilyList = [];

  List<MasterKeyModel> get historyMedicalList => _historyMedicalList;
  List<MasterKeyModel> _historyMedicalList = [];

  List<MasterKeyModel> get historySportList => _historySportList;
  List<MasterKeyModel> _historySportList = [];

  List<MasterKeyModel> get historySocialList => _historySocialList;
  List<MasterKeyModel> _historySocialList = [];

  List<MasterKeyModel> get historySurgicalList => _historySurgicalList;
  List<MasterKeyModel> _historySurgicalList = [];

  List<MasterKeyModel> listOfPhysiotherapyGoals = [];

  List<MasterKeyModel> get physicalExaminationList => _physicalExaminationList;
  List<MasterKeyModel> _physicalExaminationList = [];

  // List<MasterKeyModel> listOfPhysiotherapyGoals  = [];
  List<MasterKeyModel> listOfDiagnosisType = [];
  List<MasterKeyModel> listOfDiagnosisCondition = [];
  List<MasterKeyModel> listOfICD10 = [];
  List<MasterKeyModel> listOfTemperatureMethods = [];
  List<MasterKeyModel> listOfSpeciality = [];
  List<dynamic> listOfAdmissionType = [];
  List<dynamic> listOfDiagnosisSelectionTypes  = [];

  Future getMasterLookup(MasterKeysService masterKeys) async {
    hasError = false;
    Map<String, dynamic> body = {
      "MasterInput": masterKeys.getMasterKeyService()
    };
    await baseAppClient.post(GET_MASTER_LOOKUP_LIST,
        onSuccess: (dynamic response, int statusCode) {
      setMasterLookupInCorrectArray(
          response['MasterLookUpList']['entityList'], masterKeys);
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  setMasterLookupInCorrectArray(entryList, MasterKeysService masterKeys) {
    switch (masterKeys) {
      case MasterKeysService.Allergies:
        allergiesList.clear();
        entryList.forEach((v) {
          allergiesList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.HistoryFamily:
        _historyFamilyList.clear();
        entryList.forEach((v) {
          _historyFamilyList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.HistoryMedical:
        _historyMedicalList.clear();
        entryList.forEach((v) {
          _historyMedicalList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.HistorySocial:
        historySocialList.clear();
        entryList.forEach((v) {
          historySocialList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.HistorySports:
        _historySportList.clear();
        entryList.forEach((v) {
          _historySportList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.HistorySurgical:
        _historySurgicalList.clear();
        entryList.forEach((v) {
          _historySurgicalList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.PhysicalExamination:
        _physicalExaminationList.clear();
        entryList.forEach((v) {
          _physicalExaminationList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.AllergySeverity:
        _allergySeverityList.clear();
        entryList.forEach((v) {
          _allergySeverityList.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.physiotherapyGoals:
        listOfPhysiotherapyGoals.clear();
        entryList.forEach((v) {
          listOfPhysiotherapyGoals.add(MasterKeyModel.fromJson(v));
        });
        break;

      case MasterKeysService.DiagnosisType:
        listOfDiagnosisType.clear();
        entryList.forEach((v) {
          listOfDiagnosisType.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.DiagnosisCondition:
        listOfDiagnosisCondition.clear();
        entryList.forEach((v) {
          listOfDiagnosisCondition.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.ICD10:
        listOfICD10.clear();
        entryList.forEach((v) {
          listOfICD10.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.TemperatureMethods:
        listOfTemperatureMethods.clear();
        entryList.forEach((v) {
          listOfTemperatureMethods.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.Speciality:
        listOfSpeciality.clear();
        entryList.forEach((v) {
          listOfSpeciality.add(MasterKeyModel.fromJson(v));
        });
        break;
      case MasterKeysService.MedicationStrength:
        medicationStrengthList.clear();
        entryList.forEach((v) {
          medicationStrengthListWithModel.add(MasterKeyModel.fromJson(v));
          medicationStrengthList.add(v);
        });
        break;
      case MasterKeysService.MedicationDuration:
        medicationDurationList.clear();
        entryList.forEach((v) {
          medicationDurationList.add(v);
        });
        break;
      case MasterKeysService.MedicationRoute:
        medicationRouteList.clear();
        entryList.forEach((v) {
          medicationRouteListWithModel.add(MasterKeyModel.fromJson(v));
          medicationRouteList.add(v);
        });
        break;
      case MasterKeysService.MedicationFrequency:
        medicationFrequencyList.clear();
        entryList.forEach((v) {
          medicationFrequencyListWithModel.add(MasterKeyModel.fromJson(v));
          medicationFrequencyList.add(v);
        });
        break;
      case MasterKeysService.MedicationDoseTime:
        medicationDoseTimeList.clear();
        entryList.forEach((v) {
          medicationDoseTimeListWithModel.add(MasterKeyModel.fromJson(v));
          medicationDoseTimeList.add(v);
        });
        break;
      case MasterKeysService.MedicationIndications:
        medicationIndicationsList.clear();
        entryList.forEach((v) {
          medicationIndicationsList.add(v);
        });
        break;
      case MasterKeysService.AdmissionRequestType:
        listOfAdmissionType.clear();
        entryList.forEach((v) {
          // listOfAdmissionType.add(MasterKeyModel.fromJson(v));
          listOfAdmissionType.add(v);
        });
        break;
      case MasterKeysService.DiagnosisSelectionType:
        listOfDiagnosisSelectionTypes.clear();
        entryList.forEach((v) {
          // listOfAdmissionType.add(MasterKeyModel.fromJson(v));
          listOfDiagnosisSelectionTypes.add(v);
        });
        break;
    }
  }
}
