package com.rf.psychological.scale.resultBusiness.scaleResult;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rf.psychological.utils.Constant;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zsy
 * @description:抑郁-焦虑-压力量表
 * @date 2021/7/20 15:55
 */
public class DASSScale extends BaseScale{

    public DASSScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public  JSONObject scaleCalculate() throws Exception {
        //总得分
        int score = 0;
        //抑郁得分
        int score1 = 0;
        //焦虑得分
        int score2 = 0;
        //信赖压力得分
        int score3 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i == 0 || i == 5 || i == 7 || i == 10 || i == 11 || i == 13 || i == 17 || i == 21 || i == 26 || i == 28 || i == 31  || i == 32 || i == 34 || i == 38) {
                if (jsonObject1.getString("checkItems").equals("小部分符合")) {
                    score3 += 1;
                } else if (jsonObject1.getString("checkItems").equals("大部分符合")) {
                    score3 += 2;
                } else if (jsonObject1.getString("checkItems").equals("非常符合")) {
                    score3 += 3;
                }
            } else if (i == 1 || i == 3 || i == 6 || i == 8 || i == 14 || i == 18 || i == 19 || i == 22 || i == 24 || i == 27 || i == 29  || i == 35 || i == 39 || i == 40) {
                if (jsonObject1.getString("checkItems").equals("小部分符合")) {
                    score2 += 1;
                } else if (jsonObject1.getString("checkItems").equals("大部分符合")) {
                    score2 += 2;
                } else if (jsonObject1.getString("checkItems").equals("非常符合")) {
                    score2 += 3;
                }
            } else {
                if (jsonObject1.getString("checkItems").equals("小部分符合")) {
                    score1 += 1;
                } else if (jsonObject1.getString("checkItems").equals("大部分符合")) {
                    score1 += 2;
                } else if (jsonObject1.getString("checkItems").equals("非常符合")) {
                    score1 += 3;
                }
            }
        }
        score += score1 + score2 + score3;
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        /*resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        resultMap.put("抑郁得分", String.valueOf(score1));
        resultJson.put("抑郁得分", String.valueOf(score1));*/
        if (score1 <= 9){
            resultMap.put("抑郁指数", String.valueOf(score1)+"（正常）");
            resultJson.put("抑郁指数", String.valueOf(score1)+"（正常）");
        }else if (score1 >= 10 && score1 <= 13){
            resultMap.put("抑郁指数", String.valueOf(score1)+"（轻微）");
            resultJson.put("抑郁指数", String.valueOf(score1)+"（轻微）");
        }else if (score1 >= 14 && score1 <= 20){
            resultMap.put("抑郁指数", String.valueOf(score1)+"（中等）");
            resultJson.put("抑郁指数", String.valueOf(score1)+"（中等）");
        }else if (score1 >= 21 && score1 <= 27){
            resultMap.put("抑郁指数", String.valueOf(score1)+"（严重）");
            resultJson.put("抑郁指数", String.valueOf(score1)+"（严重）");
        }else {
            resultMap.put("抑郁指数", String.valueOf(score1)+"（非常严重）");
            resultJson.put("抑郁指数", String.valueOf(score1)+"（非常严重）");
        }
        /*resultMap.put("焦虑得分", String.valueOf(score2));
        resultJson.put("焦虑得分", String.valueOf(score2));*/
        if (score2 <= 7){
            resultMap.put("焦虑指数", String.valueOf(score2)+"（正常）");
            resultJson.put("焦虑指数", String.valueOf(score2)+"（正常）");
        }else if (score2 >= 8 && score2 <= 9){
            resultMap.put("焦虑指数", String.valueOf(score2)+"（轻微）");
            resultJson.put("焦虑指数", String.valueOf(score2)+"（轻微）");
        }else if (score2 >= 10 && score2 <= 14){
            resultMap.put("焦虑指数", String.valueOf(score2)+"（中等）");
            resultJson.put("焦虑指数", String.valueOf(score2)+"（中等）");
        }else if (score2 >= 15 && score2 <= 19){
            resultMap.put("焦虑指数", String.valueOf(score2)+"（严重）");
            resultJson.put("焦虑指数", String.valueOf(score2)+"（严重）");
        }else {
            resultMap.put("焦虑指数", String.valueOf(score2)+"（非常严重）");
            resultJson.put("焦虑指数", String.valueOf(score2)+"（非常严重）");
        }
        /*resultMap.put("压力得分", String.valueOf(score3));
        resultJson.put("压力得分", String.valueOf(score3));*/
        if (score3 <= 14){
            resultMap.put("压力指数", String.valueOf(score3)+"（正常）");
            resultJson.put("压力指数", String.valueOf(score3)+"（正常）");
        }else if (score3 >= 15 && score3 <= 18){
            resultMap.put("压力指数", String.valueOf(score3)+"（轻微）");
            resultJson.put("压力指数", String.valueOf(score3)+"（轻微）");
        }else if (score3 >= 19 && score3 <= 25){
            resultMap.put("压力指数", String.valueOf(score3)+"（中等）");
            resultJson.put("压力指数", String.valueOf(score3)+"（中等）");
        }else if (score3 >= 26 && score3 <= 33){
            resultMap.put("压力指数", String.valueOf(score3)+"（严重）");
            resultJson.put("压力指数", String.valueOf(score3)+"（严重）");
        }else {
            resultMap.put("压力指数", String.valueOf(score3)+"（非常严重）");
            resultJson.put("压力指数", String.valueOf(score3)+"（非常严重）");
        }

        List<Map<String,String>> resultMapList = new ArrayList<>();
        resultMapList.add(resultMap);

        JSONObject returnJson = new JSONObject(true);
        returnJson.put("resultMapList",resultMapList);
        returnJson.put("scaleName",Constant.SHEET_NAME_DASS_42);
        returnJson.put("resultJson",resultJson);

        return returnJson;
    }
}
