using Akka.Actor;
using Akka.Event;
using ScadaLink.Commons.Messages.RemoteQuery;

namespace ScadaLink.SiteEventLogging;

/// <summary>
/// Akka actor bridge for <see cref="IEventLogQueryService"/>.
/// Receives <see cref="EventLogQueryRequest"/> from the SiteCommunicationActor
/// and returns <see cref="EventLogQueryResponse"/>.
/// </summary>
public class EventLogHandlerActor : ReceiveActor
{
    private readonly ILoggingAdapter _log = Context.GetLogger();
    private readonly IEventLogQueryService _queryService;

    public EventLogHandlerActor(IEventLogQueryService queryService)
    {
        _queryService = queryService;

        Receive<EventLogQueryRequest>(msg =>
        {
            var response = _queryService.ExecuteQuery(msg);
            Sender.Tell(response);
        });
    }
}
