package cn.reghao.tnb.auth.app.config.redis;

import cn.reghao.tnb.common.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 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 getLoginFailedCountKey(long userId) {
        return String.format("tnb:auth:login:failed:%s:count", userId);
    }

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

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

    public static String getAuthTokenKey(long userId, String loginId) {
        return String.format("tnb:auth:login:success:%s:%s:auth_token", userId, loginId);
    }

    public static String getAccessTokenKey(long userId, String loginId) {
        return String.format("tnb:auth:login:success:%s:%s:access_token", userId, loginId);
    }

    public static String getRefreshTokenKey(long userId, String loginId) {
        return String.format("tnb:auth:login:success:%s:%s:refresh_token", userId, loginId);
    }

    public static String getAccessSignKeyKey(String accessToken) {
        return String.format("tnb:auth:jwt:sign_key:access:%s", accessToken);
    }

    public static String getRefreshSignKeyKey(String refreshToken) {
        return String.format("tnb:auth:jwt:sign_key:refresh:%s", refreshToken);
    }

    /**
     * application.yml 配置文件中
     *
     * @param
     * @return
     * @date 2025-08-28 10:30:42
     */
    public static String getRedisSessionKey(String loginId) {
        return String.format("tnb:auth:session:sessions:%s:*", loginId);
    }
}
