package com.mvc.constant;

import org.apache.commons.lang3.StringUtils;

/**
 * 设备上报信息
 * 其中0-3也用来表达表计类型
 */
public enum DeviceReportInfo {
    NON_WATER_METER("0", "非水表", 0),
    DIGITAL_AND_POINTER("1", "数字+指针表", 0),
    FULL_POINTER("2", "全指针表", 0),
    FULL_DIGITAL("3", "全数字表", 0),
    BASE_INFO_NOT_CONFIGED("87", "未配置", 0),
    IMG_REGION_NOT_CONFIGED("88", "需配区域", 0),
    CONFIGED_BUT_MOVED("89", "抄表器被动", 0),
    LOW_PROBABILITY("90", "可信度低", 0),
    CONFIGED_BUT_NOT_MAXFLOW("91", "疑似水流异常", 0),
    CONFIGED_BUT_NOT_INCREMENT("92", "疑似倒转", 0);

    DeviceReportInfo(String code, String desc, Integer type) {
        this.code = code;
        this.desc = desc;
        this.type = type;
    }

    private String code;//类型
    private String desc;//说明
    private Integer type;//类型(预留,用来控制是否让用户看到提示)

    public String getCode() {
        return code;
    }

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

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Integer getType() {
        return type;
    }

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

    /**
     * 根据code查找
     *
     * @param code
     * @return
     */
    public static DeviceReportInfo findDeviceReportInfoByCode(String code) {
        if (code == null) return null;
        for (DeviceReportInfo info : DeviceReportInfo.values()) {
            if (info.code.equals(code)) {
                return info;
            }
        }
        return null;
    }

    /**
     * 是否有效数据(识别结果为:1/2/3)
     *
     * @param code
     * @return
     */
    public static boolean isValidData(String code) {
        return StringUtils.isNotEmpty(code) && (code.equals(DIGITAL_AND_POINTER.code) || code.equals(FULL_POINTER.code) || code.equals(FULL_DIGITAL.code));
    }
}
