using foundation_system.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace foundation_system.Controllers
{
    [Authorize]
    public class ReportesController : Controller
    {
        private readonly IReporteService _reporteService;

        public ReportesController(IReporteService reporteService)
        {
            _reporteService = reporteService;
        }

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

        [HttpGet]
        public async Task<IActionResult> ArqueoCaja(DateOnly? fecha)
        {
            var fechaReporte = fecha ?? DateOnly.FromDateTime(DateTime.Today);
            var model = await _reporteService.ObtenerArqueoCajaAsync(fechaReporte);
            return View(model);
        }

        [HttpGet]
        public async Task<IActionResult> Movimientos(DateOnly? inicio, DateOnly? fin)
        {
            var fInicio = inicio ?? DateOnly.FromDateTime(DateTime.Today.AddDays(-30));
            var fFin = fin ?? DateOnly.FromDateTime(DateTime.Today);
            var model = await _reporteService.ObtenerMovimientosAsync(fInicio, fFin);
            return View(model);
        }

        [HttpGet]
        public async Task<IActionResult> HistoricoSaldos(DateOnly? inicio, DateOnly? fin)
        {
            var fInicio = inicio ?? DateOnly.FromDateTime(DateTime.Today.AddDays(-30));
            var fFin = fin ?? DateOnly.FromDateTime(DateTime.Today);
            var model = await _reporteService.ObtenerHistoricoSaldosAsync(fInicio, fFin);
            return View(model);
        }

        [HttpGet]
        public async Task<IActionResult> GastosCategoria(DateOnly? inicio, DateOnly? fin)
        {
            var fInicio = inicio ?? DateOnly.FromDateTime(DateTime.Today.AddDays(-30));
            var fFin = fin ?? DateOnly.FromDateTime(DateTime.Today);
            var model = await _reporteService.ObtenerGastosCategoriaAsync(fInicio, fFin);
            return View(model);
        }

        [HttpGet]
        public async Task<IActionResult> Reposiciones(DateOnly? inicio, DateOnly? fin)
        {
            var fInicio = inicio ?? DateOnly.FromDateTime(DateTime.Today.AddDays(-30));
            var fFin = fin ?? DateOnly.FromDateTime(DateTime.Today);
            var model = await _reporteService.ObtenerReposicionesAsync(fInicio, fFin);
            return View(model);
        }
    }
}
