using Akka.Actor;
using Akka.Event;
using ZB.MOM.WW.ScadaBridge.Commons.Messages.RemoteQuery;

namespace ZB.MOM.WW.ScadaBridge.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;

    /// <summary>Initializes the actor and registers the <see cref="EventLogQueryRequest"/> handler.</summary>
    /// <param name="queryService">The query service that executes event log queries.</param>
    public EventLogHandlerActor(IEventLogQueryService queryService)
    {
        _queryService = queryService;

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