using Microsoft.AspNetCore.SignalR;
using TrafficLightsSignalR.Hubs;
using TrafficLightsSignalR.Schema;

namespace TrafficLightsSignalR
{
    public class TrafficLightStateService : ITrafficLightStateService
    {
        private readonly IHubContext<LightHub, ILightHub> _hubContext;
        protected TrafficLightState? _state;

        public TrafficLightStateService(IHubContext<LightHub, ILightHub> hubContext)
        {
            _hubContext = hubContext;
        }

        public void SetCurrentTrafficLightState(TrafficLightState currentTrafficLightState)
        {
            _state = currentTrafficLightState;
            _hubContext.Clients.All.ReceiveStateUpdate(_state);
        }

        public TrafficLightState? GetCurrentTrafficLightState()
        {
            return _state;
        }
    }
}

