using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using VentaUniformes.Application.Exceptions;
using VentaUniformes.Application.VentasView.historico;
using VentaUniformes.Application.VentasView.historico.Borrar;

namespace VentaUniformes.app.Controllers
{
    [TypeFilter(typeof(ExceptionManager))]
    public class HistoricoController : Controller
    {
        private readonly IVentasHistoricoViewService ventashistoricoService;
        public HistoricoController(
            IVentasHistoricoViewService _ventashistoricoService
            )
        {
            ventashistoricoService = _ventashistoricoService;
        }

        [Authorize]
        [HttpGet]
        public async Task<IActionResult> Principal(VentasHistoricoViewModel model)
        {
            VentasHistoricoViewModel res;
            if (model == null || model.Top<= 0)
            {
                res = await ventashistoricoService.GetVentas();
            }
            else
            {
                res = await ventashistoricoService.GetVentas(model);
            }
                return View(res);
        }
        /*
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> Principal(VentasHistoricoViewModel model)
        {
            //verificar 
            //guardar
            //ViewData["Mensaje"] = "";
            var res = await ventashistoricoService.GetVentas(model);
            if(res==null)
            {
                ViewData["Mensaje"] = "Error al Cargar resultados";
                return View(model);
            }

            return View(res);
        }
        */
    }
}
