using System;
using System.Collections.Generic;

namespace GravCoin;

public static class NodeConsoleTickerFeed
{
	public readonly record struct Entry( string Message, string Accent, bool Highlight );

	private const int BacklogSize = 16;
	private static readonly Queue<Entry> _backlog = new();

	public static event Action<Entry> LogAdded;

	public static void PushLog( string message, bool highlight = false )
	{
		PushLog( message, "", highlight );
	}

	public static void PushLog( string message, string accent, bool highlight = false )
	{
		if ( string.IsNullOrWhiteSpace( message ) )
			return;

		var entry = new Entry( message.Trim(), accent?.Trim() ?? "", highlight );
		_backlog.Enqueue( entry );

		while ( _backlog.Count > BacklogSize )
			_backlog.Dequeue();

		LogAdded?.Invoke( entry );
	}

	public static IReadOnlyCollection<Entry> Backlog => _backlog.ToArray();
}
