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 TASScale extends BaseScale{

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

    public  JSONObject scaleCalculate() throws Exception {
        //得分
        int score = 0;
        //描述情感的能力
        int score1 = 0;
        //认识和区分情感于躯体感受的能力
        int score2 = 0;
        //幻想
        int score3 = 0;
        //外向性思维
        int score4 = 0;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject1 = jsonArray.getJSONObject(i);
            if (jsonObject1.getString("scoreDirection").equals("1")) {
                if (i == 3 || i == 7 || i == 11 || i == 21 || i == 22 || i == 25){
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 1;
                        score1 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 2;
                        score1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 4;
                        score1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 5;
                        score1 += 5;
                    }
                }else if (i == 0 || i == 2 || i == 9 || i == 13 || i == 16 || i == 19 || i == 24){
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 1;
                        score2 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 2;
                        score2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 4;
                        score2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 5;
                        score2 += 5;
                    }
                }else if (i == 1 || i == 4 || i == 14 || i == 15 || i == 17){
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 1;
                        score3 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 2;
                        score3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 4;
                        score3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 5;
                        score3 += 5;
                    }
                }else if (i == 5 || i == 6 || i == 8 || i == 10 || i == 12 || i == 18 || i == 20 || i == 23){
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 1;
                        score4 += 1;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 2;
                        score4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 4;
                        score4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 5;
                        score4 += 5;
                    }
                }
            } else if (jsonObject1.getString("scoreDirection").equals("0")) {
                if (i == 3 || i == 7 || i == 11 || i == 21 || i == 22 || i == 25) {
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 5;
                        score1 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 4;
                        score1 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score1 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 2;
                        score1 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 1;
                        score1 += 1;
                    }
                } else if (i == 0 || i == 2 || i == 9 || i == 13 || i == 16 || i == 19 || i == 24) {
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 5;
                        score2 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 4;
                        score2 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score2 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 2;
                        score2 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 1;
                        score2 += 1;
                    }
                } else if (i == 1 || i == 4 || i == 14 || i == 15 || i == 17) {
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 5;
                        score3 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 4;
                        score3 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score3 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 2;
                        score3 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 1;
                        score3 += 1;
                    }
                } else if (i == 5 || i == 6 || i == 8 || i == 10 || i == 12 || i == 18 || i == 20 || i == 23) {
                    if (jsonObject1.getString("checkItems").equals("完全不同意")) {
                        score += 5;
                        score4 += 5;
                    } else if (jsonObject1.getString("checkItems").equals("基本不同意")) {
                        score += 4;
                        score4 += 4;
                    } else if (jsonObject1.getString("checkItems").equals("既不同意，也不反对")) {
                        score += 3;
                        score4 += 3;
                    } else if (jsonObject1.getString("checkItems").equals("基本同意")) {
                        score += 2;
                        score4 += 2;
                    } else if (jsonObject1.getString("checkItems").equals("完全同意")) {
                        score += 1;
                        score4 += 1;
                    }
                }
            }
        }

        //得分列表
        Map<String, String> resultMap = new LinkedHashMap<>();
        resultMap.put("总分", String.valueOf(score));
        resultJson.put("总分", String.valueOf(score));
        System.out.println("得分：" + score);
        resultMap.put("描述情感的能力", String.valueOf(score1));
        resultJson.put("描述情感的能力", String.valueOf(score1));
        resultMap.put("认识和区分情感于躯体感受的能力", String.valueOf(score2));
        resultJson.put("认识和区分情感于躯体感受的能力", String.valueOf(score2));
        resultMap.put("幻想", String.valueOf(score3));
        resultJson.put("幻想", String.valueOf(score3));
        resultMap.put("外向性思维", String.valueOf(score4));
        resultJson.put("外向性思维", String.valueOf(score4));

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

        return returnJson;
    }
}
