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

namespace TrafficLightsSignalR.Hubs
{
    public class LightHub(ITrafficLightStateService stateService) : Hub
    {
        private readonly ITrafficLightStateService _stateService = stateService;

        public async Task GetServerState(string connectionId)
        {
            Debug.WriteLine("ServerBroadcast called...");
            string currentState = _stateService.GetCurrentTrafficLightState().CurrentSimulationTime;
            State stateTemplate = new();
            Debug.WriteLine($"Retrieved state: {currentState}");
            await Clients.Client(connectionId).SendAsync("ReceiveStructuredMessage", stateTemplate);
        }
    }
}
