namespace Febe.Core.Engine; /// One recipe run, as shown in «Appena fatto» (mockup 06). /// When it ended. /// Recipe. /// Account, when the recipe has one. /// «@marta.demo» or «Giro dei profili che segui». /// «2 storie nuove», «Nessuna novità». /// How it ended. /// New entries found. /// When it started: the entries of the account discovered from then to are /// the ones it saved (thumbnails of the Dashboard, spec §7.9). public sealed record RecentAction( DateTimeOffset At, RecipeKind Recipe, long? AccountId, string Title, string Detail, RecipeStatus Status, int NewEntries, DateTimeOffset? StartedAt = null) { /// Short label of the outcome for a badge («Scaricato», «Rimandato»...); null when nothing to say. public string? Badge => Status switch { RecipeStatus.Completed => NewEntries > 0 ? "Scaricato" : null, RecipeStatus.Denied => "Rimandato", RecipeStatus.StoppedBySignal => "Tutto fermo", RecipeStatus.TargetNotFound => "Da controllare", RecipeStatus.UnrecognizedFormat => "Formato nuovo", RecipeStatus.AccountUnreachable => "Non raggiungibile", RecipeStatus.Cancelled => "Interrotto", RecipeStatus.Failed => "Errore", RecipeStatus.NotConfigured => "Da configurare", _ => null, }; } /// The last recipe runs, newest first, in memory (the timeline keeps the full history). internal sealed class RecentActions(int capacity = 50) { private readonly Lock _gate = new(); private readonly LinkedList _items = new(); public void Add(RecentAction action) { lock (_gate) { _items.AddFirst(action); while (_items.Count > capacity) { _items.RemoveLast(); } } } public IReadOnlyList Snapshot(int limit) { lock (_gate) { return [.. _items.Take(limit)]; } } }