package com.jwipc.spe.logic;

import com.google.common.collect.Maps;
import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.runtime.function.AbstractFunction;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.Objects;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Component
public class GetRiskLevel extends AbstractFunction {
    /**
     * Get the function name
     */
    @Override
    public String getName() {
        return "getRiskLevel";
    }

    @Override
    public AviatorObject call(Map<String, Object> env) {
        Map<String, String> STR_LEVEL_RNAGE = Maps.newHashMap();
        STR_LEVEL_RNAGE.put("A", "低");
        STR_LEVEL_RNAGE.put("B", "低");
        STR_LEVEL_RNAGE.put("C", "中");
        STR_LEVEL_RNAGE.put("D", "高");
        if (Objects.nonNull(env.get("ZW_PZ_26"))) {
            return new AviatorString(STR_LEVEL_RNAGE.get(env.get("ZW_PZ_26").toString()));
        }
        return new AviatorString("");
    }

    @PostConstruct
    public void addFunction() {
        AviatorEvaluator.addFunction(new GetRiskLevel());
    }
}