using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using isn.Entities;
using isn.Data;
using System.Linq;
using isn.ViewModels;
using Unleash.ClientFactory;
using Unleash;
using isnd.Entities;
using System;
using System.Collections.Generic;
using isnd.Helpers;

namespace isn.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger _logger;
        private readonly ApplicationDbContext _dbContext;
        private readonly IUnleash _unleashĈlient;

        public HomeController(
            ApplicationDbContext dbContext,
            IOptions<UnleashClientSettings> unleashClientSettings,
            IHostingEnvironment env,
            ILogger<HomeController> logger)
        {
            _logger = logger;
            _dbContext = dbContext;
            _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value);
        }
        
        public IActionResult Index()
        {
            return View(new HomeIndexViewModel{
                PkgCount = _dbContext.Packages.Count(),
                UnleashClient = _unleashĈlient
                });
        }

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

            return View();
        }

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

            return View();
        }

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

            return View(ViewData);
        }

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