package cn.reghao.tnb.account.app.redis;

import cn.reghao.jutil.web.ServletUtil;

/**
 * @author reghao
 * @date 2023-02-03 15:57:06
 */
public class RedisKeys {
    public static String getJwtSignKey(String key) {
        return String.format("tnb:auth:jwt:rsa:%s", key);
    }

    public static String getJwtBlacklistKey(String key) {
        return String.format("tnb:auth:jwt:blacklist:%s", key);
    }

    public static String getCaptchaKey() {
        String sessionId = ServletUtil.getSessionId();
        return String.format("tnb:account:code:%s:captcha", sessionId);
    }

    public static String getVerifyCodeKey(int channel, String receiver) {
        String sessionId = ServletUtil.getSessionId();
        return String.format("tnb:account:code:%s:channel:%s:receiver:%s", sessionId, channel, receiver);
    }

    public static String getPubkeyRKey() {
        String sessionId = ServletUtil.getSessionId();
        return String.format("tnb:account:rsa:r:%s", sessionId);
    }

    public static String getRsaPubkeyKey() {
        return String.format("tnb:account:rsa:pubkey");
    }

    public static String getRsaPrikeyKey() {
        return String.format("tnb:account:rsa:prikey");
    }

    public static String getLoginSuccessKey(long userId, int plat, String loginId) {
        return String.format("tnb:account:login:success:%s:%s:%s", userId, plat, loginId);
    }

    public static String getLoginSuccessKey(String sessId) {
        return String.format("tnb:account:login:success:%s", sessId);
    }

    public static String getLoginSuccessKeyPattern(long userId, Integer plat) {
        return String.format("tnb:account:login:success:%s:%s:*", userId, plat);
    }

    public static String getLoginSuccessKeyPattern(long userId) {
        return String.format("tnb:account:login:success:%s:*", userId);
    }

    public static String getLoginFailedCountKey(String userId, int plat) {
        return String.format("tnb:account:login:failed:count:%s:%s", userId, plat);
    }

    public static String getLoginFailedLockKey(String userId, int plat) {
        return String.format("tnb:account:login:failed:lock:%s:%s", userId, plat);
    }

    public static String getAccessSignKeyKey(String accessToken) {
        return String.format("tnb:account:login:signkey:access:%s", accessToken);
    }

    public static String getRefreshSignKeyKey(String refreshToken) {
        return String.format("tnb:account:login:signkey:refresh:%s", refreshToken);
    }

    public static String getAccessTokenKey(String userId, String loginId) {
        return String.format("tnb:account:login:%s:accesstoken:%s", userId, loginId);
    }

    public static String getRefreshTokenKey(String userId, String loginId) {
        return String.format("tnb:account:login:%s:refreshtoken:%s", userId, loginId);
    }

    public static String getAuthTokenKey(String userId, Integer plat, String loginId) {
        return String.format("tnb:account:login:%s:authtoken:%s:%s", userId, plat, loginId);
    }

    public static String getRedisSessionKey(String loginId) {
        return String.format("tnb:account:session:sessions:%s:*", loginId);
    }
}
