using Microsoft.AspNetCore.SignalR;
using System.Diagnostics;
using TrafficLightsSignalR.Schema;

namespace TrafficLightsSignalR.Hubs
{
    public class LightHub : Hub<ILightHub>
    {
        private readonly ITrafficLightStateService _stateService;
        private readonly ILogger<LightHub> _logger;

        public LightHub(ITrafficLightStateService stateService, ILogger<LightHub> logger)
        {
            _stateService = stateService;
            _logger = logger;
        }

        public async Task GetServerState(string connectionId)
        {
            var currentState = _stateService.GetCurrentTrafficLightState();
            _logger.LogInformation($"Request for server state received, current state null?: ${currentState is null}");
            await Clients.Client(connectionId).ReceiveServerState(currentState);
        }
    }
}
