package cn.ey.biz.module.system.dal.redis;

import cn.ey.biz.framework.redis.core.RedisKeyDefine;
import cn.ey.biz.module.system.dal.dataobject.oauth2.OAuth2AccessTokenDO;
import cn.ey.biz.module.system.dal.dataobject.user.AdminUserDO;

import java.time.Duration;

import static cn.ey.biz.framework.redis.core.RedisKeyDefine.KeyTypeEnum.HASH;
import static cn.ey.biz.framework.redis.core.RedisKeyDefine.KeyTypeEnum.STRING;

/**
 * System Redis Key 枚举类
 */
public interface RedisKeyConstants {

    String DICT_DATA_CACHE_NAME = "dict_data";
    String DICT_DATA_CACHE_NAME_CATEGORY = DICT_DATA_CACHE_NAME + ":category";
    String DICT_DATA_CACHE_NAME_CATEGORY_DATA = DICT_DATA_CACHE_NAME + ":category_data";
    String DICT_VERSION_CACHE_NAME = "dict_version";
    String DICT_REFRESH_VERSION_KEY = "refresh_version";
    String DICT_VERSION_LOCK_PREFIX = DICT_VERSION_CACHE_NAME + ":lock";

    // 用户组的缓存
    String SYSTEM_USER_GROUP_KEY = "system:user:group";

    RedisKeyDefine OAUTH2_ACCESS_TOKEN = new RedisKeyDefine("访问令牌的缓存",
            "oauth2_access_token:%s", // 参数为访问令牌 token
            STRING, OAuth2AccessTokenDO.class, RedisKeyDefine.TimeoutTypeEnum.DYNAMIC);

    RedisKeyDefine SOCIAL_AUTH_STATE = new RedisKeyDefine("社交登陆的 state", // 注意，它是被 JustAuth 的 justauth.type.prefix 使用到
            "social_auth_state:%s", // 参数为 state
            STRING, String.class, Duration.ofHours(24)); // 值为 state

    RedisKeyDefine SWITCH_USER = new RedisKeyDefine("切换用户的缓存",
            "system:switch_user:%s.%s",
            STRING, Long.class, Duration.ofMinutes(5));

    RedisKeyDefine DICT_VERSION = new RedisKeyDefine("公共字典版本的缓存",
            DICT_VERSION_CACHE_NAME + ":%s",
            HASH, Long.class, RedisKeyDefine.TimeoutTypeEnum.FOREVER);

    RedisKeyDefine DICT_PUBLIC_DATA = new RedisKeyDefine("公共字典数据的缓存",
            DICT_DATA_CACHE_NAME + ":%s",
            STRING, String.class, Duration.ofHours(24));

    RedisKeyDefine SYSTEM_USER = new RedisKeyDefine("用户中心的缓存",
            "system:user:%s",
            STRING, AdminUserDO.class, Duration.ofHours(24));

    RedisKeyDefine CODE_BLOCK = new RedisKeyDefine("合法codeBlock的缓存",
            "system:code:block:%s",
            STRING, String.class, Duration.ofHours(24));

    RedisKeyDefine FILE = new RedisKeyDefine("临时文件的缓存",
            "system:file:%s.%s",
            STRING, Long.class, Duration.ofMinutes(1));

}
