namespace Admin.NET.Plugin.AiDOP.Infrastructure.S8;
///
/// S8-SEVERITY-FOLLOW-SERIOUS-STANDARDIZE-EXEC-1:S8 异常 severity 业务枚举。
/// 当前阶段只保留 FOLLOW(关注)/ SERIOUS(严重)两档;
/// 旧值 LOW/MEDIUM/HIGH/CRITICAL 仅作为 legacy 兼容输入,新写入必须落 FOLLOW/SERIOUS。
///
public static class S8SeverityCode
{
public const string Follow = "FOLLOW";
public const string Serious = "SERIOUS";
/// 归一化:旧值/空值/新值 -> FOLLOW / SERIOUS。空值默认 FOLLOW。
public static string Normalize(string? code)
{
if (string.IsNullOrWhiteSpace(code)) return Follow;
return code.Trim().ToUpperInvariant() switch
{
"FOLLOW" => Follow,
"LOW" => Follow,
"MEDIUM" => Follow,
"SERIOUS" => Serious,
"HIGH" => Serious,
"CRITICAL" => Serious,
_ => Follow,
};
}
public static bool IsFollow(string? code) => Normalize(code) == Follow;
public static bool IsSerious(string? code) => Normalize(code) == Serious;
/// 新值或旧值合法(用于 legacy 查询参数兼容)。
public static bool IsValid(string? code)
{
if (string.IsNullOrWhiteSpace(code)) return false;
return code.Trim().ToUpperInvariant() switch
{
"FOLLOW" or "SERIOUS" or "LOW" or "MEDIUM" or "HIGH" or "CRITICAL" => true,
_ => false,
};
}
public static string Label(string? code) => Normalize(code) switch
{
Serious => "严重",
_ => "关注",
};
public static object[] Options() =>
new[] { Follow, Serious }
.Select(v => new { value = v, label = Label(v) })
.ToArray