package com.jiayue.ssi.constant;

import com.jiayue.ssi.dto.ActiveUserDto;
import com.jiayue.ssi.entity.SysBlacklist;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 缓存的key 常量
 *
 * @author ruoyi
 */
public class CacheConstants {
    /**
     * 登录用户 redis key
     */
    public static final String LOGIN_TOKEN_KEY = "login_tokens:";

    /**
     * 验证码 redis key
     */
    public static final String CAPTCHA_CODE_KEY = "captcha_codes:";

    /**
     * 邮箱口令 key
     */
    public static final String MAIL_CODE_KEY = "mail_codes:";
    /**
     * 非活动退出 key
     */
    public static final String REACTIVE_KEY = "reactive:";
    /**
     * 防止邮箱口令频繁访问
     */
    public static final String PREVENT_MAIL_CODE = "prevent_mail_codes:";

    /**
     * 参数管理 cache key
     */
    public static final String SYS_CONFIG_KEY = "sys_config:";

    /**
     * 字典管理 cache key
     */
    public static final String SYS_DICT_KEY = "sys_dict:";

    /**
     * 防重提交 redis key
     */
    public static final String REPEAT_SUBMIT_KEY = "repeat_submit:";

    /**
     * 限流 redis key
     */
    public static final String RATE_LIMIT_KEY = "rate_limit:";

    /**
     * 登录账户密码错误次数 redis key
     */
    public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:";
//    /**
//     * 服务端心跳
//     */
//    public static final String HEART_KEY = "heart:";
    /**
     * 登录token存储，map<用户名，token:授权时间>
     */
    public static Map<String,String> LOGIN_TOKEN_MAP = new ConcurrentHashMap<String,String>();
    /**
     * 是否使用邮箱口令 默认：true使用
     */
    public static boolean use_send_mail = true;

    /**
     * ip黑名单缓存<ip,对象>
     */
    public static ConcurrentMap<String, SysBlacklist> blacklistMap = new ConcurrentHashMap<>();

    /**
     * 用户名对应明文密码缓存
     */
    public static ConcurrentMap<String, String> usernamePasswordMap = new ConcurrentHashMap<>();
    /**
     * 当前服务端访问的IP集合<IP,用户名>
     */
    public static ConcurrentMap<String, String> IP_USER_MAP = new ConcurrentHashMap<>();
//    /**
//     * 用于用户心跳
//     */
//    public static Map<String, ActiveUserDto> ACTIVE_USER_MAP = new ConcurrentHashMap<String,ActiveUserDto>();
    /**
     * 用于被踢用户的request存储
     */
    public static Map<String, HttpServletRequest> KICKED_USER_MAP = new ConcurrentHashMap<String, HttpServletRequest>();
}
