package com.microservices.common.core.constant;

/**
 * 缓存常量信息
 *
 * @author microservices
 */
public class CacheConstants {
    /**
     * 缓存有效期，默认720（分钟）
     */
    public final static long EXPIRATION = 720;

    /**
     * 缓存刷新时间，默认120（分钟）
     */
    public final static long REFRESH_TIME = 120;

    /**
     * 密码最大错误次数
     */
    public final static int PASSWORD_MAX_RETRY_COUNT = 5;

    /**
     * 密码锁定时间，默认10（分钟）
     */
    public final static long PASSWORD_LOCK_TIME = 10;

    /**
     * 权限缓存前缀
     */
    public final static String LOGIN_TOKEN_KEY = "login_tokens:";
    /**
     * Gitlink令牌缓存前缀
     */
    public final static String GITLINK_ACCESS_TOKEN = "gitlink_tokens:";

    /**
     * 获取Token缓存key
     */
    public static String getTokenKey(String token) {
        return CacheConstants.LOGIN_TOKEN_KEY + token;
    }

    /**
     * 角色的菜单权限缓存前缀
     */
    public final static String ROLE_MENU_PERMISSIONS_KEY = "role_menu_permissions:";

    /**
     * 根据角色Key获取菜单权限
     */
    public static String getRoleMenuPermissionsKey(String roleKey) {
        return CacheConstants.ROLE_MENU_PERMISSIONS_KEY + roleKey;
    }

    /**
     * 用户身份列表缓存前缀
     */
    public final static String USER_IDENTIFY_LIST_KEY = "user_identify_list:";

    /**
     * 获取用户身份列表缓存key
     */
    public static String getUserIdentifyListKey(String username) {
        return CacheConstants.USER_IDENTIFY_LIST_KEY + username;
    }

    /**
     * 更新文章间隔前缀
     */
    public final static String UPDATE_DOC_INTERVAL_KEY = "updateDocIntervalKey:";

    /**
     * 通过专区Id获取专区详情JSON对象
     */
    public final static String ZONE_JSON_OF_ZONE_ID_KEY = "zoneJSONOfZoneId:";

    /**
     * 通过组织Id获取专区详情JSON对象
     */
    public final static String ZONE_JSON_OF_DEPT_ID_KEY = "zoneJSONOfDeptId:";
    /**
     * 内容管理同步缓存前缀
     */
    public final static String CMS_SYNC_DEPT_ID_KEY = "cmsSyncDeptId:";

    /**
     * GitLink项目详情缓存前缀
     */
    public final static String GITLINK_PROJECT_DETAIL_KEY = "gitlink_project_detail:";

    /**
     * 验证码 redis key
     */
    public static final String CAPTCHA_CODE_KEY = "captcha_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 PWD_ERR_CNT_KEY = "pwd_err_cnt:";

    /**
     * 登录IP黑名单 cache key
     */
    public static final String SYS_LOGIN_BLACKIPLIST = SYS_CONFIG_KEY + "sys.login.blackIPList";

    /**
     * 文件类型 sys_dict key
     */
    public static final String SYS_DICT_FILE_TYPE = "file_type";
    /**
     * GitLink项目属性 sys_dict key
     */
    public static final String SYS_DICT_GITLINK_PROJECT_PROPERTIES = "gitlink_project_properties";

    /**
     * 组织类型-特色专区
     */
    public static final int DEPT_TYPE_TSZQ = 1;

    /**
     * 组织类型-项目管理
     */
    public static final int DEPT_TYPE_PMS = 2;

    /**
     * 特色专区字典 zone key
     */
    public static final String ZONE_KEY_ID = "zone_key_id";

    /**
     * 特色专区模板字典 template key
     */
    public static final String ZONE_TEMPLATE = "zone_template";

    /**
     * 特色专区模板字典 template key
     */
    public static final String ZONE_TEMPLATE_DEFAULT_LABEL = "通用模板";

    /**
     * 特色专区会员邀请Token前缀
     */
    public final static String ZONE_MEMBER_INVITATION_TOKEN_KEY = "zone_member_invitation_token:";
    /**
     * 特色专区会员邀请前缀
     */
    public final static String ZONE_MEMBER_INVITATION_KEY = "zone_member_invitation:";
    /**
     * 企业IdRedis Key前缀
     */
    public final static String ENTERPRISE_ID_KEY = "enterprise_id_key:";

    public static String getEnterpriseIdKey(Long id) {
        return ENTERPRISE_ID_KEY + id;
    }

    /**
     * 锁定企业下制品库 Key前缀
     */
    public final static String LOCK_ENTERPRISE_IDENTIFIER_REPO_ID_KEY = "lock_enterprise_identifier_repo_id_key:";

    public static String getLockEnterpriseIdentifierRepoIdKey(String enterpriseIdentifier, Long repoId) {
        return LOCK_ENTERPRISE_IDENTIFIER_REPO_ID_KEY + enterpriseIdentifier + ":" + repoId;
    }

    /**
     * 锁定制品库制品 Key前缀
     */
    public final static String LOCK_PRODUCT_LIBRARY_ID_COMPONENT_ID_KEY = "lock_product_library_id_component_id_key:";

    public static String getLockProductLibraryIdComponentIdKey(Long productRepoId, String componentId) {
        return LOCK_PRODUCT_LIBRARY_ID_COMPONENT_ID_KEY + productRepoId + ":" + componentId;
    }

    /**
     * 企业标识Redis Key前缀
     */
    public final static String ENTERPRISE_IDENTIFIER_KEY = "enterprise_identifier_key:";

    public static String getEnterpriseIdentifierKey(String identifier) {
        return ENTERPRISE_IDENTIFIER_KEY + identifier;
    }

    /**
     * Nexus请求携带Id Key前缀
     */
    public final static String NEXUS_GLOBAL_TID_KEY = "nexus_global_tid_key";


    /**
     * Gitlink组织开通企业是否完成 Key前缀
     */
    public final static String GITLINK_ORG_ID_OPEN_ENTERPRISE_KEY = "gitlink_org_id_open_enterprise_key:";

    public static String getGitlinkOrgIdOpenEnterpriseKey(Long gitlinkOrgId) {
        return GITLINK_ORG_ID_OPEN_ENTERPRISE_KEY + gitlinkOrgId;
    }

    /**
     * 专区项目Gitlink信息 Key前缀
     */
    public final static String ZONE_PROJECT_GITLINK_INFO = "zone_project_gitlink_info:";
    /**
     * 专区下项目分数排序 Key前缀
     */
    public final static String ZONE_PROJECT_SORT_BY_SCORE = "zone_project_sort_by_score:";

    public static String getZoneProjectGitlinkInfo(Long gitlinkProjectId) {
        return ZONE_PROJECT_GITLINK_INFO + gitlinkProjectId;
    }

    public static String getZoneProjectSortByScore(String date, Long zoneId, Long projectTypeId) {
        return ZONE_PROJECT_SORT_BY_SCORE + date + ":" + zoneId + ":" + projectTypeId;
    }

    public static String getAllZoneProjectSortByScore(Long zoneId) {
        return ZONE_PROJECT_SORT_BY_SCORE + "*:" + zoneId + ":*";
    }

    // 全局资源数据缓存，最近一年统计数据
    public final static String GLOBAL_RESOURCES_DATA_KEY = "GLOBAL_RESOURCES_DATA:";

    public static String getGlobalResourcesDataKey(String startDate, String endDate) {
        return GLOBAL_RESOURCES_DATA_KEY + startDate + "_TO_" + endDate;
    }
}
