namespace PlotLine.ViewModels; public sealed record WarningCluster(string Title,IReadOnlyList Warnings) { public int Active=>Warnings.Count(w=>!w.IsDismissed&&!w.IsIntentional&&!w.IsAcknowledged); public int Scenes=>Warnings.Select(w=>w.CurrentSceneId??w.SceneID).Where(id=>id.HasValue).Distinct().Count(); } public static class WarningTriage { // Grouping is navigational evidence, never a claim that warnings share one cause. public static IReadOnlyList Group(IEnumerable warnings)=>warnings .GroupBy(w=>$"{w.Severity}|{(string.IsNullOrWhiteSpace(w.WarningType)?w.WarningTypeDisplayName:w.WarningType)}|{w.EntityType}|{w.CharacterID}|{w.AssetID}|{(w.CharacterID.HasValue||w.AssetID.HasValue?null:w.SceneID)}",StringComparer.OrdinalIgnoreCase) .Select(g=>new WarningCluster(g.First().WarningTypeDisplayName+" ยท "+(!string.IsNullOrWhiteSpace(g.First().CharacterName)?g.First().CharacterName:!string.IsNullOrWhiteSpace(g.First().EntityType)?g.First().EntityType:"Story evidence"),g.OrderByDescending(w=>w.LastDetectedDate).ToArray())) .OrderByDescending(g=>g.Active).ThenByDescending(g=>g.Warnings.Count).ThenBy(g=>g.Title).ToArray(); }