using Furion.DataEncryption;
using Furion.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Waste.Application
{
    public class AuthorizationManager : IAuthorizationManager, ITransient
    {
        /// <summary>
        /// 检查权限
        /// </summary>
        /// <param name="ResourceId"></param>
        /// <returns></returns>
        public bool CheckSecurity(string ResourceId)
        {
            throw new NotImplementedException();
        }
        /// <summary>
        /// 生成token
        /// </summary>
        /// <returns></returns>
        public LoginSuccessInfo Encrypt(UserInfo userInfo)
        {
            var accesstoken = JWTEncryption.Encrypt(new Dictionary<string, object>() {
                {"UserId",userInfo.UserId },
                {"AccountType",userInfo.AccountType },
                {"BusinessId",userInfo.BusinessId },
                {"IsSuper",userInfo.IsSuper },
                {"RealName",userInfo.RealName },
                {"RoleId",userInfo.RoleId }
            });
            //刷新token,30天有效期
            var refreshToken = JWTEncryption.GenerateRefreshToken(accesstoken, 30);
            return new LoginSuccessInfo { 
                token=accesstoken,
                refreshtoken=refreshToken
            };
        }
    }
}
