using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NuGet.Versioning;
using isnd.Data;
using isnd.Entities;
using Unleash;
using isnd.Services;
using isnd.ViewModels;
using System.Threading.Tasks;
using isnd.Interfaces;
using isn.Abstract;

namespace isnd.Controllers
{
    [AllowAnonymous]
    public partial class PackagesController : Controller
    {
        const int maxTake = 100;
        private readonly Resource[] resources;
        private readonly ILogger<PackagesController> logger;
        private readonly IDataProtector protector;

        private readonly IsndSettings isndSettings;
        readonly ApplicationDbContext dbContext;
        private readonly IPackageManager packageManager;
        private readonly IUnleash unleashĈlient;

        public PackagesController(
            ILoggerFactory loggerFactory,
            IDataProtectionProvider provider,
            IOptions<IsndSettings> isndOptions,
            IUnleash unleashĈlient,
            ApplicationDbContext dbContext,
            IPackageManager pm)
        {
            logger = loggerFactory.CreateLogger<PackagesController>();
            isndSettings = isndOptions.Value;
            protector = provider.CreateProtector(isndSettings.ProtectionTitle);
            this.dbContext = dbContext;
            packageManager = pm;
            this.unleashĈlient = unleashĈlient;
            resources = packageManager.GetResources(unleashĈlient).ToArray();
        }
    }
}
