using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using isnd.Data;
using System.Linq;
using isnd.ViewModels;
using Unleash;
using System.Reflection;
using Microsoft.EntityFrameworkCore;

namespace isnd.Controllers
{
    /// <summary>
    /// Home Controller
    /// </summary>
    public class HomeController : Controller
    {
        private readonly ApplicationDbContext _dbContext;
        private readonly IUnleash _unleashĈlient;
        /// <summary>
        /// Home controller ctor
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="unleashĈlient"></param>

        public HomeController(
            ApplicationDbContext dbContext,
            IUnleash unleashĈlient)
        {
            _dbContext = dbContext;
            _unleashĈlient = unleashĈlient;
        }
        
        public IActionResult Index()
        {
            return View(new HomeIndexViewModel{
                PkgCount = _dbContext.Packages
                .Where(p => p.Versions.Count > 0)
                .Count(),
                UnleashClient = _unleashĈlient
                });
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";
            var ass = typeof(isn.Abstract.Resource).GetType().Assembly;
            var attrs = ass.GetCustomAttributes(true);
            // ass.GetCustomAttributes(true);
            System.Reflection.AssemblyFileVersionAttribute v = (AssemblyFileVersionAttribute) 
            GetType().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute));

            return View();
        }

        public IActionResult Privacy()
        {
            ViewData["Message"] = "Your Privacy page.";

            return View(ViewData);
        }

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



