using Microsoft.AspNetCore.Mvc;
using ReportingServices.Shared.Models.PlanningReport;
using ReportingServices.Shared.HelperClasses;

namespace ReportingServices.UI.Controllers
{
    public class PlanningReportController : Controller
    {
        private readonly string _baseUrl = "https://localhost:7196/api/ScrapeDB/";

        public IActionResult Index()
        {
            return View();
        }

        public async Task<IActionResult> WeeklyPartChangesReport(DateTime startDate, DateTime endDate)
        {
            string partChangeUrl = _baseUrl + "PartChanges?startDate=" + startDate.ToString() + "&endDate=" + endDate.ToString();
            string psnwoRunsUrl = _baseUrl + "PSNWO?startDate=" + startDate.ToString() + "&endDate=" + endDate.ToString();

            int numberOfPartChanges = await ApiCaller.GetApi<int>(partChangeUrl);
            List<ReactorPSNWORuns> reactorPSNWORuns = await ApiCaller.GetApi<List<ReactorPSNWORuns>>(psnwoRunsUrl);

            WeeklyPartChanges weeklyPartChanges = new()
            {
                TotalPartChanges = numberOfPartChanges,
                StartDate = startDate.ToShortDateString(),
                EndDate = endDate.ToShortDateString(),
                ReactorPSNWORuns = reactorPSNWORuns
            };

            return View(weeklyPartChanges);
        }
    }
}
