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

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

        public ConsoleHandler(IMemoryBus 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);
            }
        }
    }
}