package com.huatek.busi.task.transformer.utils.accessories;

import com.google.common.collect.Maps;
import com.huatek.busi.task.transformer.utils.CommonUtils;
import com.huatek.busi.util.EvaluateConstant;
import com.huatek.busi.vo.BusiParamTransformerVo;
import com.huatek.busi.vo.TransformerEvaluateDataVo;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;

import java.util.Map;

/**
 * @ClassName: NonElectricQuantityProtectionDevice
 * @Description: 变压器附件-非电量保护装置..
 * @Author: Arno
 * @Date:  2023/10/10 15:44
 * @version V1.0
 */
@Slf4j
public class NonElectricQuantityProtectionDevice {




    public static Map<String, Object> calcNonElectricQuantityWeight(TransformerEvaluateDataVo transformerEvaluateDataVo, Map<String, BusiParamTransformerVo> secondLevelMap,
                                                           Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step) {
        double byqfjkg = 0d;
        //二级类型
        BusiParamTransformerVo secondVo = CommonUtils.getEvaluateObject(EvaluateConstant.BYQ_FDLBHZZ, secondLevelMap);
        if (null != secondVo) {
            if (CommonUtils.checkAttend(secondVo)) {
                Map<String, Object> threeResultMap = calcThree(transformerEvaluateDataVo, threeLevelMap, jsonArray, step);
                return CommonUtils.calcSecond(secondVo, threeResultMap, jsonArray, "变压器附件-非电量保护装置权重计算");
            }
        }
        log.error("-->变压器附件-非电量保护装置未设置评估参数");
        return null;

    }


    public static Map<String, Object> calcThree(TransformerEvaluateDataVo vo, Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step) {
        //继电器动作
        String relayAction = vo.getRelayAction();
        //压力释放阀动作
        String reliefValveAction = vo.getRelayAction();

        Double calcWeight = calc(relayAction, EvaluateConstant.BYQ_FDLBHZZ_JDQDZ, "继电器动作", threeLevelMap, jsonArray, step, "变压器附件-非电量保护装置-油击穿电压变化率（Kv，%）权量计算结果");
        Double calcWeight2 = calc(reliefValveAction, EvaluateConstant.BYQ_FDLBHZZ_YLSFDZ, "压力释放阀动作", threeLevelMap, jsonArray, step, "变压器附件-非电量保护装置-传动机构有无问题(Y/N)权重计算结果");

        Double total = calcWeight + calcWeight2 ;
        log.info("-->>变压器附件-非电量保护装置-分项和计算结果: [{}]", total);
        step += 1;
        return CommonUtils.buildResult(step, total);
    }

    public static Double calc(String value, String type, String typeDesc, Map<String, BusiParamTransformerVo> threeLevelMap, JSONArray jsonArray, int step, String stepName) {
        Double aDouble = CommonUtils.calcItemResult(value, type, typeDesc, threeLevelMap, jsonArray, step, stepName);
        log.info("-->>变压器附件-非电量保护装置-{}计算结果{}", typeDesc, aDouble);
        return aDouble;
    }

}
