using Microsoft.UI; using Microsoft.UI.Xaml.Media; namespace RblxTool.Models; public sealed class FeedLine { private static readonly SolidColorBrush Neutral = new(Colors.Gainsboro); private static readonly SolidColorBrush Good = new(Colors.LightGreen); private static readonly SolidColorBrush Warn = new(Colors.Goldenrod); private static readonly SolidColorBrush Bad = new(Colors.IndianRed); private static readonly SolidColorBrush Accent = new(Colors.DeepSkyBlue); public FeedLine(string text, FeedTone tone = FeedTone.Neutral) { Text = text; Brush = tone switch { FeedTone.Good => Good, FeedTone.Warn => Warn, FeedTone.Bad => Bad, FeedTone.Accent => Accent, _ => Neutral, }; } public string Text { get; } public SolidColorBrush Brush { get; } public static FeedLine From(JobEvent item) => item.Type switch { "log" => new FeedLine( $" {item.Message}", item.Level switch { "warn" => FeedTone.Warn, "error" => FeedTone.Bad, _ => FeedTone.Neutral, }), "item_found" => new FeedLine( $" found {item.Id,-12} {Clip(item.Name, 44)} {item.Price,6} R$ {Clip(item.Creator, 18)}", FeedTone.Accent), "purchase" => new FeedLine( item.Success ? $" bought {item.Id,-12} {Clip(item.Name, 44)} {item.Price,6} R$" : $" skip {item.Id,-12} {Clip(item.Name, 44)} {item.Detail}", item.Success ? FeedTone.Good : FeedTone.Warn), "group_found" => new FeedLine( $" group {item.Id,-12} {Clip(item.Name, 44)} {item.Members,8} members entry {(item.PublicEntry ? "open" : "closed")}", FeedTone.Accent), "job_finished" => new FeedLine( $" done scanned {item.Scanned} matched {item.Matched} acted {item.Purchased} {item.ElapsedMs} ms", FeedTone.Good), _ => new FeedLine($" {item.Type}"), }; private static string Clip(string? value, int max) { if (string.IsNullOrEmpty(value)) { return string.Empty; } return value.Length <= max ? value.PadRight(max) : value[..(max - 1)] + "…"; } } public enum FeedTone { Neutral, Good, Warn, Bad, Accent, }