using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace HuanMeng.DotNetCore.JwtInfrastructure.Interface
{
    /// <summary>
    /// jwt帮助类
    /// </summary>
    public interface IJwtAuthManager
    {
        /// <summary>
        /// 用户刷新令牌只读词典
        /// </summary>
        IImmutableDictionary<string, JwtRefreshToken> UsersRefreshTokensReadOnlyDictionary { get; }

        /// <summary>
        /// 生成令牌
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="claims">用户的有关信息</param>
        /// <param name="now"></param>
        /// <returns></returns>
        JwtAuthResult GenerateTokens(string username, Claim[] claims, DateTime now);
        /// <summary>
        /// 刷新令牌
        /// </summary>
        /// <param name="refreshToken"></param>
        /// <param name="accessToken"></param>
        /// <param name="now"></param>
        /// <returns></returns>
        JwtAuthResult Refresh(string refreshToken, string accessToken, DateTime now);
        /// <summary>
        /// 删除过期的刷新令牌
        /// </summary>
        /// <param name="now"></param>
        void RemoveExpiredRefreshTokens(DateTime now);
        /// <summary>
        /// 按用户名删除刷新令牌
        /// </summary>
        /// <param name="userName"></param>
        void RemoveRefreshTokenByUserName(string userName);
        /// <summary>
        /// 解码JwtToken
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        (ClaimsPrincipal, JwtSecurityToken?) DecodeJwtToken(string token);
    }
}
