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

namespace Insight.Web.Network.Handlers;

public class ConsoleHandler : IMessageHandler<WebSession>
{
    private readonly Bus _bus;

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

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