using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using ReportService.Models;

namespace ReportService.Controllers
{
    public class HomeController:Controller
    {
        private readonly ILogger<HomeController> _logger;


        public HomeController(ILogger<HomeController> logger) {
            _logger = logger;
        }

        public IActionResult Index(string uid,string un,string reportName) {
            uid ??= "";
            un ??= "";
            reportName ??= "";
            Response.Cookies.Append("_userCK",$"{{\"uid\":\"{uid}\",\"un\":\"{un}\"}}");
            Response.Cookies.Append("_initReport",reportName);
            this._logger.LogInformation($"Home_Index:uid:{uid}:un:{un}");
            return View();
        }

        [ResponseCache(Duration = 0,Location = ResponseCacheLocation.None,NoStore = true)]
        public IActionResult Error() {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
