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;

/**
 * @description 威廉斯创造力倾向测评量表
 */
public class WILLScale extends BaseScale {
    public WILLScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public JSONObject scaleCalculate() throws Exception {
        //冒险得分
        int scoreA = 0;
        //好奇得分
        int scoreB = 0;
        //想象得分
        int scoreC = 0;
        //挑战性得分
        int scoreD = 0;
        //总分
        int score = 0;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 0 || i == 4 || i == 20 || i == 23 || i == 24 || i == 27 || i == 28 || i == 34 || i == 35 || i == 42 || i == 43) {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreA += 3;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreA += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreA += 1;
                    }
                } else if (i == 1 || i == 7 || i == 10 || i == 11 || i == 18 || i == 26 || i == 32 || i == 33 || i == 36 || i == 37 || i == 38 || i == 46 || i == 47 || i == 48) {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreB += 3;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreB += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreB += 1;
                    }
                } else if (i == 5 || i == 12 || i == 13 || i == 15 || i == 19 || i == 21 || i == 22 || i == 29 || i == 30 || i == 31 || i == 39 || i == 44 || i == 45) {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreC += 3;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreC += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreC += 1;
                    }
                } else {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreD += 3;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreD += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreD += 1;
                    }
                }
            } else {
                if (i == 0 || i == 4 || i == 20 || i == 23 || i == 24 || i == 27 || i == 28 || i == 34 || i == 35 || i == 42 || i == 43) {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreA += 1;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreA += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreA += 3;
                    }
                } else if (i == 1 || i == 7 || i == 10 || i == 11 || i == 18 || i == 26 || i == 32 || i == 33 || i == 36 || i == 37 || i == 38 || i == 46 || i == 47 || i == 48) {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreB += 1;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreB += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreB += 3;
                    }
                } else if (i == 5 || i == 12 || i == 13 || i == 15 || i == 19 || i == 21 || i == 22 || i == 29 || i == 30 || i == 31 || i == 39 || i == 44 || i == 45) {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreC += 1;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreC += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreC += 3;
                    }
                } else {
                    if (jsonObject1.getString("checkItems").equals("完全符合")) {
                        scoreD += 1;
                    } else if (jsonObject1.getString("checkItems").equals("部分符合")) {
                        scoreD += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全不符合")) {
                        scoreD += 3;
                    }
                }
            }
        }
        score = scoreA + scoreB + scoreC + scoreD;
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("冒险得分", String.valueOf(scoreA));
        resultMap.put("好奇心得分", String.valueOf(scoreB));
        resultMap.put("想象力得分", String.valueOf(scoreC));
        resultMap.put("挑战性得分", String.valueOf(scoreC));
        resultMap.put("总分", String.valueOf(score));

        resultJson.put("冒险得分", String.valueOf(scoreA));
        resultJson.put("好奇心得分", String.valueOf(scoreB));
        resultJson.put("想象力得分", String.valueOf(scoreC));
        resultJson.put("挑战性得分", String.valueOf(scoreC));
        resultJson.put("总分", String.valueOf(score));

        if (score < 111) {
            resultMap.put("合计分结论", "创造力倾向一般。");
            resultJson.put("合计分结论", "创造力倾向一般。");
        } else if (score <= 133) {
            resultMap.put("合计分结论", "创造力潜力良好。");
            resultJson.put("合计分结论", "创造力潜力良好。");
        } else {
            resultMap.put("合计分结论", "有很大的创造性潜能。");
            resultJson.put("合计分结论", "有很大的创造性潜能。");
        }



        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_WILL);
        returnJson.put("resultJson", resultJson);

        return returnJson;
    }
}
