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

namespace InABox.Core
{
    public interface INotificationHandler
    {
        /// <summary>
        /// Receives a new notification from the server, called when a notification is pushed.
        /// </summary>
        /// <param name="o">The notification object</param>
        void Receive(object? o);
    }

    public class NotificationHandler<TNotification> : INotificationHandler
    {
        public delegate void ReceiveEvent(TNotification notification);

        public event ReceiveEvent? OnReceive;

        public NotificationHandler() { }

        public NotificationHandler(ReceiveEvent receive)
        {
            OnReceive += receive;
        }

        public void Receive(object? notification) => Receive((TNotification)notification);

        /// <summary>
        /// Receives a new notification from the server, called when a notification is pushed.
        /// </summary>
        /// <param name="notification">The notification received</param>
        public void Receive(TNotification notification)
        {
            OnReceive?.Invoke(notification);
        }
    }
}
