package com.djhk.common.constant;

/**
 * @author szh
 * @version 1.0
 * @date 2023/4/13
 */
public class RedisConstant {

    public static final String DELIMITER = ":";

    public static final Integer DEVICE_ALIVE_SECOND = 60;

    public static final Integer WEBSOCKET_ALIVE_SECOND = 60 * 60 * 24;

    public static final String USER_SELECTED_PREFIX = "user" + DELIMITER + "organ" + DELIMITER;

    // 规则：SMS_CODE_LOGIXTICS:模板编号:手机号
    public static final String SMS_CODE_PREFIX = "SMS_CODE_FLIGHT:%s:%s";

    public static final String SMS_CODE_LIMIT = "SMS_CODE_FLIGHT_LIMIT:%s:%s";

    //ip 黑名单
    public static final String IP_CHECK_BLACK = "IP_CHECK:%s:BLACK";

    public static final String IP_CHECK_BLACK_LEVEL = "IP_CHECK:%s:BLACK_LEVEL";

    //IP 请求次数校验
    public static final String IP_CHECK_REQUEST_TIMES = "IP_CHECK:%s:REQUEST_TIMES" + DELIMITER + "%s";

    //用户登录账号黑名单
    public static final String LOGIN_CHECK_ACCOUNT_BLACK = "LOGIN_CHECK_ACCOUNT:%s:BLACK";

    //用户登录IP黑名单
    public static final String LOGIN_CHECK_IP_BLACK = "LOGIN_CHECK_IP:%s:BLACK";

    public static final String LOGIN_CHECK_IP_ACCOUNT_BLACK = "LOGIN_CHECK_IP_ACCOUNT:%s:%s:BLACK";

    //用户锁定级别
    public static final String LOGIN_CHECK_ACCOUNT_BLACK_LEVEL = "LOGIN_CHECK_ACCOUNT:%s:BLACK_LEVEL";

    //用户登录错误次数-密码
    public static final String LOGIN_CHECK_ACCOUNT_WRONG_TIMES_PASSWORD = "LOGIN_CHECK_ACCOUNT:%s:WRONG_TIMES_PASSWORD";

    //用户登录错误次数-短信
    public static final String LOGIN_CHECK_ACCOUNT_WRONG_TIMES_SMS = "LOGIN_CHECK_ACCOUNT:%s:%s:WRONG_TIMES_MESSAGE";

    //ip登录错误次数
    public static final String LOGIN_CHECK_IP_WRONG_TIMES = "LOGIN_CHECK_IP:%s:WRONG_TIMES";

    //反制设备
    public static final String COUNTER_PREFIX = "counter"+ DELIMITER;

    public static String getSmsCodeKey(String phoneNo,String templateCodeIndex) {
        return String.format(SMS_CODE_PREFIX,templateCodeIndex,phoneNo);
    }

    public static String getSmsCodeLimitKey(String phoneNo,String templateCodeIndex) {
        return String.format(SMS_CODE_LIMIT,templateCodeIndex,phoneNo);
    }

    public static String getIpCheckBlackKey(String ip) {
        return String.format(IP_CHECK_BLACK,ip);
    }

    public static String getLoginCheckIpAccountBlackKey(String ip,String account) {
        return String.format(LOGIN_CHECK_IP_ACCOUNT_BLACK,ip,account);
    }

    public static String getIpCheckBlackLevelKey(String ip) {
        return String.format(IP_CHECK_BLACK_LEVEL,ip);
    }

    public static String getIpCheckRequestTimesKey(String ip,int seconds) {
        return String.format(IP_CHECK_REQUEST_TIMES,ip,seconds);
    }

    public static String getLoginCheckIpWrongTimesKey(String ip) {
        return String.format(LOGIN_CHECK_IP_WRONG_TIMES,ip);
    }

    public static String getLoginCheckAccountWrongTimesSmsKey(String ip,String account) {
        return String.format(LOGIN_CHECK_ACCOUNT_WRONG_TIMES_SMS,ip,account);
    }

    public static String getLoginCheckAccountWrongTimesPasswordKey(String account) {
        return String.format(LOGIN_CHECK_ACCOUNT_WRONG_TIMES_PASSWORD,account);
    }

    public static String getLoginCheckIpBlackKey(String ip) {
        return String.format(LOGIN_CHECK_IP_BLACK,ip);
    }
    public static String getLoginCheckAccountBlackLevelKey(String account) {
        return String.format(LOGIN_CHECK_ACCOUNT_BLACK_LEVEL,account);
    }
    public static String getLoginCheckAccountBlackKey(String account) {
        return String.format(LOGIN_CHECK_ACCOUNT_BLACK,account);
    }
}
