package cn.cecep.talroad.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.*;

/**
 * @author pick-x
 */

public enum EnvironmentalCodingGradeEnum {

    // 来源三监联动系统
     SJLDXT_01("SJLD","SJLDXT_01",false,50,"无证排污")
    ,SJLDXT_02("SJLD","SJLDXT_02",false,20,"执行报告未按照排污许可证规定的内容、频次、时间要求提交")
    ,SJLDXT_03("SJLD","SJLDXT_03",false,20,"许可证到期未延续")
    ,SJLDXT_04("SJLD","SJLDXT_04",false,20,"未按照许可证规定如实公开污染物排放信息")
    ,SJLDXT_05("SJLD","SJLDXT_05",false,20,"排污限期整改通知书到期整改未完成")
    ,SJLDXT_06("SJLD","SJLDXT_06",false,20,"执行报告中出现超总量排污行为")
    ,SJLDXT_07("SJLD","SJLDXT_07",false,20,"环评手续不齐全")
    ,SJLDXT_08("SJLD","SJLDXT_08",false,20,"企业基本信息与排污许可证不一致")
    ,SJLDXT_09("SJLD","SJLDXT_09",false,20,"排污许可证填报产能超过环评批复文件")
    ,SJLDXT_10("SJLD","SJLDXT_10",false,20,"实际现场主要生产设施、废气或废水污染物治理设施与排污许可证不一致")
    ,SJLDXT_11("SJLD","SJLDXT_11",false,20,"企业现场排污口不规范")
    ,SJLDXT_12("SJLD","SJLDXT_12",false,20,"企业环境管理台账不规范")
    ,SJLDXT_13("SJLD","SJLDXT_13",false,20,"污染物排放标准、重点污染物总量控制要求发生变化，未及时变更排污许可证")
    ,SJLDXT_14("SJLD","SJLDXT_14",false,20,"自行监测频次不满足许可证要求")
    ,SJLDXT_15("SJLD","SJLDXT_15",false,20,"未按照许可证规定制定自行监测方案并开展自行监测")
    ,SJLDXT_16("SJLD","SJLDXT_16",false,20,"监督性监测数据超标")
    ,SJLDXT_17("SJLD","SJLDXT_17",false,10,"执法部门根据年度执法计划发现排污单位自行监测数据存疑并需要对排污单位进行监测")

    // 来源在线监测系统 BJB 代表报警表
    ,ZXJCXT_01("ZXJCXT","ZXJCXT_01",true,10,"污染源数据超标")

    // 来源分表计电系统
    ,FBJDXT_01("FBJDXT","FBJDXT_01",true,10, "分表计电发生报警问题")

    // 来源执法系统
    ,ZFXT_01("G","ZFXT_01",true,10, "双随机检查发现问题")
    ,ZFXT_02("G","ZFXT_02",true,10, "企业核查发现问题")

    // 来源关联分析系统
    ,GLFXXT_01("GLFXXT","GLFXXT_01",true,20, "排污单位自行监测数据超标")
    ,GLFXXT_02("GLFXXT","GLFXXT_02",true,1, "数据质量异常预警")
    ,GLFXXT_03("GLFXXT","GLFXXT_03",true,5, "每日数据传输率低于75%")
    ,GLFXXT_04("GLFXXT","GLFXXT_04",true,10, "设备启停未报备")

    ;
    /**
     * 编码
     */
    private String code;
    private String type;

    private String name;
    private Integer grade;

    /**
     * 是否多次扣分
     */
    private Boolean isGrade;

    /**
     * 查询报警表的内容
     */
    private static Map<String,List<String>> initQueryCondition = new HashMap<>();

    EnvironmentalCodingGradeEnum() {
        initQueryCondition();
    }
    public void initQueryCondition() {
        initQueryCondition.put(GLFXXT_02.code,Arrays.asList(new String[]{"006001", "006002", "006003", "006004"}));
        initQueryCondition.put(GLFXXT_02.code,Arrays.asList(new String[]{"002002"}));
    }

    public static List<String> getInitQueryCondition(String key) {
        return initQueryCondition.get(key);
    }

    /**
     * @Author: Mr.Yanghongtao
     * @data: 2023/4/8 3:20 PM
     * @Deseription: 获取三监联动问题，不能多次扣分的
     * @Params: null
     * @Return:
     * @Throws:
     */
    public static List<String> getNameListByType (String type,Boolean isGrade) {
        List<String> names = new ArrayList<>();
        for (EnvironmentalCodingGradeEnum e : EnvironmentalCodingGradeEnum.values()) {
            if (type.equals(e.getType()) && (isGrade == null ? 1==1 : isGrade.equals(e.getIsGrade()))) {
                names.add(e.getName());
            }
        }
        return names;
    }

    /**
     * @Author: Mr.Yanghongtao
     * @data: 2023/4/8 3:20 PM
     * @Deseription: 通过code获取list
     * @Params: null
     * @Return:
     * @Throws:
     */
    public static List<EnvironmentalCodingGradeEnum> getListByCode (String code,Boolean isGrade) {
        List<EnvironmentalCodingGradeEnum> names = new ArrayList<>();
        for (EnvironmentalCodingGradeEnum e : EnvironmentalCodingGradeEnum.values()) {
            if (e.getCode().equals(code) && (isGrade == null ? 1==1 : isGrade.equals(e.getIsGrade()))) {
                names.add(e);
            }
        }
        return names;
    }


    /**
     * @Author: Mr.Yanghongtao
     * @data: 2023/4/8 7:06 PM
     * @Deseription: 通过名称查询Code
     * @Params: null
     * @Return:
     * @Throws:
     */
    public static String getCodeByName(String name) {
        for (EnvironmentalCodingGradeEnum e : EnvironmentalCodingGradeEnum.values()) {
            if (name.equals(e.getName()) ) {
               return e.getCode();
            }
        }
        return null;
    }
    /**
     * @Author: Mr.Yanghongtao
     * @data: 2023/4/8 7:06 PM
     * @Deseription: 通过名称查询Code
     * @Params: null
     * @Return:
     * @Throws:
     */
    public static String getTypeByName(String name) {
        for (EnvironmentalCodingGradeEnum e : EnvironmentalCodingGradeEnum.values()) {
            if (name.equals(e.getType()) ) {
               return e.getCode();
            }
        }
        return null;
    }

    /**
     * @Author: Mr.Yanghongtao
     * @data: 2023/4/8 2:07 PM
     * @Deseription: 通过名称获取要扣的分数
     * @Params: null
     * @Return:
     * @Throws:
     */
    public static Integer getGradeByName(String name) {
        if (StringUtils.isNotBlank(name)) {
            for (EnvironmentalCodingGradeEnum e : EnvironmentalCodingGradeEnum.values()) {
                if (name.equals(e.getName())) {
                    return e.getGrade();
                }
            }
        }
        return 0;
    }

    EnvironmentalCodingGradeEnum(String type, String code,  Boolean isGrade, Integer grade, String name){
        this.code = code;
        this.name = name;
        this.grade = grade;
        this.isGrade = isGrade;
        this.type = type;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getGrade() {
        return grade;
    }

    public void setGrade(Integer grade) {
        this.grade = grade;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Boolean getIsGrade() {
        return isGrade;
    }

    public void setIsGrade(Boolean isGrade) {
        this.isGrade = isGrade;
    }

}
