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

namespace ReportingServices.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class FabTimeController : ControllerBase
    {
        private readonly IFabTimeReportingRepository _fabTimeReportingRepository;
        private readonly IScrapeDatabaseRepository _scrapeDBRepository;

        public FabTimeController(IFabTimeReportingRepository fabTimeReportingRepository, IScrapeDatabaseRepository scrapeDBRepository)
        {
            _fabTimeReportingRepository = fabTimeReportingRepository;
            _scrapeDBRepository = scrapeDBRepository;
        }

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

            return yieldInformation;
        }

        [HttpGet("ToolStateTrend")]
        public async Task<List<EquipmentStateByDay>> GetToolStateTrendData(string toolType)
        {
            return await _fabTimeReportingRepository.GetToolStateTrendData(toolType);
        }

        [HttpGet("ToolState")]
        public async Task<List<ToolStateCurrent>> GetToolStateData(string toolType)
        {
            return await _fabTimeReportingRepository.GetToolStateData(toolType);
        }

        [HttpGet("Testing")]
        public string Testing()
        {
            return "This Works!";
        }
    }
}
