using MediatR;
using Microsoft.AspNetCore.SignalR;
using Sledgemapper.Api.Hubs;
using Sledgemapper.Api.Notifications;
using System.Threading;
using System.Threading.Tasks;
using Sledgemapper.Shared.Clients;

namespace Sledgemapper.Api.Handlers
{
    public class SendDeleteOverlayMessage : INotificationHandler<DeleteOverlayNotification>
    {
        private readonly IHubContext<SledgemapperHub, ISledgemapperClient> _hub;

        public SendDeleteOverlayMessage(IHubContext<SledgemapperHub, ISledgemapperClient> hub) => _hub = hub;

        public async Task Handle(DeleteOverlayNotification notification, CancellationToken cancellationToken)
        {
            await _hub.Clients.Groups(notification.Session.SessionId.ToString()).DeleteOverlay(notification.Overlay);
        }
    }
}
