using System;
using System.Collections.Generic;
using System.Text;

namespace InABox.Core
{
    /// <summary>
    /// Client-side push manager.
    /// </summary>
    public class PushHandlers
    {
        private Dictionary<Type, IPushHandler> Handlers = new Dictionary<Type, IPushHandler>();

        public void AddHandler<TPush>(PushHandler<TPush> handler)
        {
            Handlers[typeof(TPush)] = handler;
        }
        public void AddHandler<TPush>(PushHandler<TPush>.ReceiveEvent receive)
        {
            Handlers[typeof(TPush)] = new PushHandler<TPush>(receive);
        }

        public void Push(Type type, object? push)
        {
            if (Handlers.TryGetValue(type, out var handler))
            {
                handler.Receive(push);
            }
        }
    }
}
