import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/privilege/HMCProjectListModel.dart';
import 'package:hmg_patient_app/core/model/privilege/PrivilegeModel.dart';
import 'package:hmg_patient_app/core/model/privilege/ProjectDetailListModel.dart';
import 'package:hmg_patient_app/core/model/privilege/VidaPlusProjectListModel.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';
import 'package:hmg_patient_app/main.dart';

class PrivilegeService extends BaseService {
  List<PrivilegeModel> privilegeModelList = [];
  List<VidaPlusProjectListModel> vidaPlusProjectListModel = [];
  List<HMCProjectListModel> hMCProjectListModel = [];
  List<ProjectDetailListModel> projectDetailListModel = [];

  Future getPrivilege() async {
    Map<String, dynamic> body = Map();
    body['PatientType'] = 4;
    body['LanguageID'] = 1;
    await baseAppClient.post(GET_PRIVILEGE, onSuccess: (dynamic response, int statusCode) {
      response['ServicePrivilegeList'].forEach((item) {
        privilegeModelList.add(PrivilegeModel.fromJson(item));
      });

      if (response['ProjectListVidaPlus'].length != 0) {
        response['ProjectListVidaPlus'].forEach((item) {
          vidaPlusProjectListModel.add(VidaPlusProjectListModel.fromJson(item));
        });
      }

      if (response['HMCProjectList'].length != 0) {
        response['HMCProjectList'].forEach((item) {
          hMCProjectListModel.add(HMCProjectListModel.fromJson(item));
        });
      }

      if (response['ProjectDetailList'].length != 0) {
        response['ProjectDetailList'].forEach((item) {
          projectDetailListModel.add(ProjectDetailListModel.fromJson(item));
        });
      }
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
