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 PLPScale extends BaseScale {
    public PLPScale(JSONArray jsonArray, JSONObject resultJson) {
        super(jsonArray, resultJson);
    }

    public JSONObject scaleCalculate() throws Exception {
        //愤世嫉俗
        int scoreA = 0;
        //值得信任
        int scoreB = 0;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i == 0 || i == 2 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12 || i == 14 || i == 15 || i == 18) {
                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 (jsonObject1.getString("checkItems").equals("稍微不同意")) {
                    scoreA += -1;
                } else if (jsonObject1.getString("checkItems").equals("部分不同意")) {
                    scoreA += -2;
                } else if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                    scoreA += -3;
                }

            } else {
                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 (jsonObject1.getString("checkItems").equals("稍微不同意")) {
                    scoreB += -1;
                } else if (jsonObject1.getString("checkItems").equals("部分不同意")) {
                    scoreB += -2;
                } else if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                    scoreB += -3;
                }
            }
        }


        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("愤世嫉俗", String.valueOf(scoreA));
        resultJson.put("愤世嫉俗", String.valueOf(scoreA));
        resultMap.put("值得信任", String.valueOf(scoreB));
        resultJson.put("值得信任", String.valueOf(scoreB));


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

        return returnJson;
    }
}
