package com.unis.detectionnum.server.aenum;

import java.util.List;

/**
 * 告警级别
 */
public enum AlarmLevel {
    NONE(0, "none alarm"), RED(1, "red alarm"), ORANGE(2, "orange alarm"), 
    YELLOW(3, "yellow alarm"), BLUE(4,"blue alarm");
    private int id;

    private String name;

    private AlarmLevel(final int id, final String name) {
        this.id = id;
        this.name = name;
    }

    /**
     * @return the id
     */
    public final int getId() {
        return this.id;
    }

    /**
     * @return the name
     */
    public final String getName() {
        return this.name;
    }

    /**
     * 根据alarm level id 查找AlarmLevel.
     * @param id AlarmLevel.id
     * @return AlarmLevel
     */
    public static AlarmLevel parse(final int id) {
        for (final AlarmLevel alarmLevel : AlarmLevel.values()) {
            if (id == alarmLevel.getId()) {
                return alarmLevel;
            }
        }
        return null;
    }

    /**
     * 从list中选出告警级别最高的告警. <br/>
     * @author johnnyking39
     * @param levels List&lt;AlarmLevel>
     * @return AlarmLevel
     */
    public static AlarmLevel selectSeverityAlarmLevel(final List<AlarmLevel> levels) {
        if (null == levels) {
            return null;
        }
        AlarmLevel level = null;
        for (final AlarmLevel alarmLevel : levels) {
            if (null == level) {
                level = alarmLevel;
                continue;
            }
            if (NONE == level) {
                level = alarmLevel;
                continue;
            }
            if (NONE == alarmLevel) {
                continue;
            }
            if (level.compareTo(alarmLevel) >= 0) {
                level = alarmLevel;
                continue;
            }
        }
        return level;
    }

}
