using Microsoft.AspNetCore.Mvc;
using ReportingServices.Shared.Models.PlanningReport;
using ReportingServices.Shared.Models.ProductionReport;
using ReportingServices.Shared.Repositories;

namespace ReportingServices.API.Controllers;

[Route("api/[controller]")]
[ApiController]
public class ScrapeDBController : ControllerBase
{
    private readonly IScrapeDatabaseRepository _scrapeDBRepository;

    public ScrapeDBController(IScrapeDatabaseRepository scrapeDBRepository) => _scrapeDBRepository = scrapeDBRepository;

    [HttpGet("ReactorOuts")]
    public YieldInformation GetReactorOuts(string startDate, string endDate)
    {
        List<ReactorOutsByRDS> outs = _scrapeDBRepository.GetRDSRunBetweenDates(startDate, endDate);
        YieldInformation yieldInformation = new()
        {
            Outs = outs,
            Scrap = _scrapeDBRepository.GetScrapByDay(outs)
        };

        return yieldInformation;
    }

    [HttpGet("PSNWO")]
    public List<ReactorPSNWORuns> GetReactorPSNWORuns(string startDate, string endDate) => _scrapeDBRepository.GetReactorPSNWORuns(startDate, endDate);

    [HttpGet("PartChanges")]
    public int GetNumberOfPartChanges(string startDate, string endDate) => _scrapeDBRepository.GetNumberOfPartChanges(startDate, endDate);

    [HttpGet("Targets")]
    public QuarterlyTargets GetQuarterlyTargets() => _scrapeDBRepository.GetQuarterlyTargets();

    [HttpGet("Reactors")]
    public List<Reactor> GetReactors() => _scrapeDBRepository.GetReactors();

    [HttpGet("RDS")]
    public List<RDS> GetRDSForLastDay(string date) => _scrapeDBRepository.GetRDSForLastDay(date);

    [HttpGet("ReactorEvents")]
    public List<ReactorEvent> GetReactorEvents(string startDate, string endDate, string reactorNumber) => _scrapeDBRepository.GetReactorEvents(startDate, endDate, reactorNumber);

    [HttpGet("GetLastUpTransaction")]
    public int GetLastUpTransaction(string reactorNumber) => _scrapeDBRepository.GetLastUpTransaction(reactorNumber);

    [HttpGet("ToolEvents")]
    public ToolEvent GetLatestToolEvent(string toolID) => _scrapeDBRepository.GetLatestToolEvent(toolID);

    [HttpGet("GetOutsAndScrapTotals")]
    public OutsAndScrapTotal GetOutsAndScrapTotal(string startDate, string endDate) => _scrapeDBRepository.GetOutsAndScrapTotals(startDate, endDate);

    [HttpGet("GetQuarterStartDate")]
    public DateTime GetQuarterStartDate() => _scrapeDBRepository.GetQuarterStartDate();

    [HttpGet("GetCurrentHoldLots")]
    public List<HoldLot> GetCurrentHoldLots() => _scrapeDBRepository.GetCurrentHoldLots();

    [HttpGet("GetCurrentHotWORunning")]
    public List<string> GetCurrentHotWORunning() => _scrapeDBRepository.GetCurrentHotWORunning();

    [HttpGet("GetScheduledEvents")]
    public List<ScheduledEvent> GetScheduledEvents(string startDate, string endDate) => _scrapeDBRepository.GetScheduledEvents(startDate, endDate);

    [HttpGet("GetReactorPartChanges")]
    public List<ReactorPSNWORuns> GetReactorPartChanges(string startDate, string endDate) => _scrapeDBRepository.GetReactorPartChanges(startDate, endDate);

    [HttpGet("GetProjectedPartChanges")]
    public List<ReactorPSNWORuns> GetProjectedPartChanges(string startDate, string endDate) => _scrapeDBRepository.GetProjectedPartChanges(startDate, endDate);
}