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

    public JSONObject scaleCalculate() throws Exception {
        //消极应对NC得分
        int scoreA = 0;
        //积极应对PC得分
        int scoreB = 0;

        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (i == 1 || i == 3 || i == 5 || i == 6 || i == 9 || i == 11 || i == 12 || i == 16 || i == 15 || i == 18) {
                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("是")) {
                    scoreA += 4;
                } else if (jsonObject1.getString("checkItems").equals("肯定是")) {
                    scoreA += 5;
                }
            } else {
                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 (jsonObject1.getString("checkItems").equals("是")) {
                    scoreB += 4;
                } else if (jsonObject1.getString("checkItems").equals("肯定是")) {
                    scoreB += 5;
                }
            }
        }
        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("消极应对NC得分", String.valueOf(scoreA));
        resultMap.put("积极应对PC得分", String.valueOf(scoreB));
        resultJson.put("消极应对NC得分", String.valueOf(scoreA));
        resultJson.put("积极应对PC得分", 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_TCSQ);
        returnJson.put("resultJson", resultJson);

        return returnJson;
    }
}
