using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Client
{
  /// <summary>
  /// Service permettant d'afficher des toasts dans l'application.
  /// </summary>
  public class NotificationManager
  {
    private Queue<string> _messages = new Queue<string>();

    public IReadOnlyList<string> Messages => _messages.ToArray();

    public event Action OnChange;

    public void Add(string message)
    {
      _messages.Enqueue(message);

      Task.Run(async () =>
      {
        await Task.Delay(3000);
        _messages.Dequeue();
        OnChange?.Invoke();
      });

      OnChange?.Invoke();
    }
  }
}