using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace TrafficLights.Pages
{
    public class GetStatusModel : PageModel
    {
        private readonly TrafficLightSimulatorService _trafficLightSimulatorService;
        public GetStatusModel(TrafficLightSimulatorService trafficLightSimulatorService)
        {
            _trafficLightSimulatorService = trafficLightSimulatorService; 
        }
        public IActionResult OnGet()
        {
            var currentStatus = _trafficLightSimulatorService.GetStatus();
            var data = new
            {
                currentPeriodName = currentStatus.CurrentPeriod.Name,
                currentPeriodVerboseName = currentStatus.CurrentPeriod.VerboseName,
                currentStateData = currentStatus.CurrentState,
                currentStateIndex = currentStatus.CurrentStateIndex,
                secondsUntilChangeover = currentStatus.SecondsUntilChangeover,
                simulationTime = currentStatus.SimulationTime.ToString()
            };

            return new JsonResult(currentStatus);
        }
    }
}
