using Fuel.Application.Service;
using FuelServer.Core.Entity;
using Microsoft.Extensions.DependencyInjection;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Fuel.Core
{
    public  class Authorization
    {
        private   IUserService _userService;
        private IApplyService _applyService;

        //public Authorization(IUserService userService)
        //{
        //    _userService = ServiceLocator.GetRequiredService<IUserService>();
        //}
        //public static  List<string> GetPermissions()
        //{
        //    var permissions =   _userService.GetUserPermissions();
        //    return permissions;
        //}
        public Authorization(IUserService userService,IApplyService applyService)
        {
            _userService = userService;
            _applyService = applyService;
        }

        public List<string> GetPermissions()
        {
            var permissions = _userService.GetUserPermissions();
            return permissions;
        }
        public AdApply GetApply(string appid)
        {
            var apply = _applyService.GetApply(appid);
            return apply;
        }

    }
    public static class ServiceLocator
    {
        public static IServiceProvider ServiceProvider { get; set; }

        public static T GetRequiredService<T>() where T : notnull
        {
            if (ServiceProvider == null)
            {
                throw new InvalidOperationException("");
            }
            return ServiceProvider.GetRequiredService<T>();
        }
    }

}
