using Insight.Domain.Interfaces;
using Insight.Domain.Network;
using Insight.Domain.Network.Agent.Messages;
using Vaitr.Bus;

namespace Insight.Web.Network.Broker.Handlers;

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

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

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