package com.test.common.enums;

/**
 * @author liangdaliang
 * @Description：缺陷严重程度枚举
 * @date 2025-04-23 14:06
 */
public enum EnumSeverityLevel {
    INVALID("0", "无效"),
    MINOR("1", "轻微"),
    MODERATE("2", "一般"),
    SEVERE("3", "严重"),
    CRITICAL("4", "致命");

    private final String code;
    private final String description;

    EnumSeverityLevel(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据严重程度码获取枚举实例
     */
    public static EnumSeverityLevel fromCode(String code) {
        for (EnumSeverityLevel level : values()) {
            if (level.code.equals(code)) {
                return level;
            }
        }
        throw new IllegalArgumentException("无效的严重程度码: " + code);
    }

    /**
     * 根据状态码直接获取中文描述
     */
    public static String getDescriptionByCode(String code) {
        return fromCode(code).getDescription();
    }
}
