using Insight.Web.Interfaces;
using Insight.Web.Messages;
using Vaitr.Bus;

namespace Insight.Web.Network.Handlers
{
    public class ConsoleHandler : IWebMessageHandler<WebSession>
    {
        private readonly Bus _bus;

        public ConsoleHandler(Bus bus)
        {
            _bus = bus;
        }

        public async ValueTask HandleAsync<TMessage>(WebSession sender, TMessage message, CancellationToken cancellationToken) where TMessage : IWebMessage
        {
            if (message is ConsoleQueryProxy consoleQuery)
            {
                await _bus.PublishAsync(consoleQuery, cancellationToken);
            }
        }
    }
}