using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using isnd.Data;
using isnd.Entities;
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;

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