package com.microservices.zone.utils;

/**
 * @author otto
 */
public class ZoneConstants {
    public final static String PROJECT_PROPERTIES_ARRAY_KEY = "array";
    public final static String PROJECT_PROPERTIES_HTTP_KEY = "http";
    public final static String ARRAY_SPLIT_SYMBOLS = ",";
    public final static String PROJECT_PROPERTIES_POINT_KEY = "\\.";
    /**
     * 会员审核状态-审核通过
     */
    public final static String MEMBER_AUDIT_PASS = "1";
    /**
     * 会员审核状态-审核未通过
     */
    public final static String MEMBER_AUDIT_FAILED = "2";
    /**
     * 会员审核状态-待审核
     */
    public final static String MEMBER_NOT_AUDIT = "0";
    /**
     * 会员审核状态-邀请中
     */
    public final static String MEMBER_AUDIT_INVITED = "3";
    /**
     * GitLink响应总数Key
     */
    public final static String GITLINK_RESPONSE_TOTAL_COUNT_KEY = "total_count";
    /**
     * GitLink响应总数Key
     */
    public final static String GITLINK_RESPONSE_COUNT_KEY = "count";
    /**
     * GitLink项目列表Key
     */
    public final static String GITLINK_RESPONSE_PROJECTS_KEY = "projects";
    /**
     * 否
     */
    public final static String FALSE = "0";
    /**
     * 是
     */
    public final static String TRUE = "1";
    /**
     * 默认分类
     */
    public final static String DEFAULT_TYPE_NAME = "默认分类";
    /**
     * 资源类型-其他文件
     */
    public final static String RESOURCE_TYPE_OTHER_FILE = "其他文件";
    /**
     * 文件后缀对应资源类型的Redis缓存Key前缀
     */
    public final static String REDIS_KEY_FILE_SUFFIX_OF_RESOURCE_TYPE_PREFIX = "file_suffix_of_zone_resource_type:";

    /**
     * Redis Key前缀-每日首次访问积分标记
     */
    public final static String ZONE_DAILY_FIRST_VISIT_KEY = "zone:points:daily:visit:";

    /**
     * Redis Key前缀-积分异步任务队列
     */
    public final static String ZONE_POINTS_ASYNC_QUEUE_KEY = "zone:points:async:queue";

    /**
     * Redis Key前缀-积分异步任务重试队列
     */
    public final static String ZONE_POINTS_ASYNC_QUEUE_RETRY_KEY = "zone:points:async:queue:retry";

    /**
     * 积分任务最大重试次数
     */
    public final static int ZONE_POINTS_MAX_RETRY_COUNT = 3;

    /**
     * 重试间隔配置（毫秒）：index=重试次数-1
     * 1分钟 -> 5分钟 -> 15分钟
     */
    public final static long[] ZONE_POINTS_RETRY_DELAYS = {
            60_000L,
            300_000L,
            900_000L
    };

    // ==================== 积分操作类型 ====================
    public static class TransactionType {
        public static final String ADD = "add";
        public static final String DEDUCT = "deduct";
        public static final String FREEZED = "freezed";
        public static final String UNFREEZED = "unfreezed";
    }

    // ==================== 积分事件状态 ====================
    public static class EventStatus {
        public static final String PROCESSING = "processing";
        public static final String SUCCESS = "success";
        public static final String FAIL = "fail";
    }

    // ==================== 会员入会审核 ====================
    public static class MemberAudit {
        public static final String SOURCE_TYPE = "createAccount";
        public static final String SUBJECT = "入会审核通过";
        public static final String SUBJECT_DESC = "管理员审核通过";
        public static final String REASON_TEMPLATE = "成为专区会员 +%d分";
        public static final int POINTS = 5;
    }

    // ==================== 每日首次访问 ====================
    public static class DailyVisit {
        public static final String SOURCE_TYPE = "dailyVisit";
        public static final String SUBJECT = "每日登录奖励";
        public static final String SUBJECT_DESC = "首次加载专区页面触发";
        public static final String REASON_TEMPLATE = "每日首次访问专区 +%d分，上限1次/天";
        public static final int POINTS = 1;
    }

    // ==================== 文章浏览（阅读量奖励）====================
    public static class DocVisits {
        public static final String SOURCE_TYPE = "visitsDoc";
        public static final String SUBJECT = "文章阅读量奖励";
        public static final String SUBJECT_DESC_TEMPLATE = "《%s》· 累计阅读 %d 次";
        public static final String REASON_TEMPLATE = "每满 100 次阅读 +%d 分，已累计获取 %d 分";
        public static final int POINTS = 2;
        public static final int TRIGGER_VISITS = 100;
        public static final int MAX_TRIGGER_COUNT = 25;
        public static final int POINTS_PER_TRIGGER = 2;
    }

    // ==================== 发布文章审核通过 ====================
    public static class PublishDoc {
        public static final String SOURCE_TYPE = "publishDoc";
        public static final String SUBJECT = "发布文章通过审核";
        public static final String SUBJECT_DESC_TEMPLATE = "文章：%s";
        public static final String REASON = "发布文章审核通过，积分已发放";
        public static final int POINTS = 5;
    }

    // ==================== 文章被设为精选 ====================
    public static class FeaturedDoc {
        public static final String SOURCE_TYPE = "featuredDoc";
        public static final String SUBJECT = "文章被设为精选";
        public static final String SUBJECT_DESC_TEMPLATE = "《%s》管理员标记";
        public static final String REASON = "文章被设为精选，积分已发放";
        public static final int POINTS = 5;
    }

    // ==================== 发布资源审核通过 ====================
    public static class PublishResource {
        public static final String SOURCE_TYPE = "publishResource";
        public static final String SUBJECT = "发布资源通过审核";
        public static final String SUBJECT_DESC_TEMPLATE = "资源：%s";
        public static final String REASON = "资源附件审核通过，积分已发放";
        public static final int POINTS = 5;
    }

    // ==================== 资源下载奖励 ====================
    public static class DownloadResource {
        public static final String SOURCE_TYPE = "downloadResource";
        public static final String SUBJECT = "资源下载奖励";
        public static final String SUBJECT_DESC_TEMPLATE = "%s · 下载量达 %s 次";
        public static final String REASON_TEMPLATE = "每下载 1 次 +%d 分，已累计获取 %d 分";
        public static final int POINTS = 1;
        public static final int POINTS_LIMIT = 100;
    }

    // ==================== 关联项目 ====================
    public static class RelevanceProject {
        public static final String SOURCE_TYPE = "relevanceProject";
        public static final String SUBJECT = "关联项目";
        public static final String SUBJECT_DESC_TEMPLATE = "项目：%s";
        public static final String REASON = "个人项目成功关联，奖励 10 分已到账";
        public static final int POINTS = 10;
    }

    // ==================== 电子荣誉证书兑换 ====================
    public static class CertificateRedeem {
        public static final String SOURCE_TYPE = "certificateRedeem";
        public static final String SUBJECT = "专属电子荣誉证书";
        public static final String SUBJECT_DESC = "专属电子荣誉证书已发放";
        public static final String REASON = "兑换成功，电子荣誉证书已发放";
        public static final int POINTS = 200;
    }

    // ==================== 线下沙龙活动报名冻结 ====================
    public static class OfflineActivity {
        public static final String SOURCE_TYPE = "offlineActivityFreeze";
        public static final String SUBJECT = "线下沙龙报名（预约冻结）";
        public static final String REASON = "申请审核中，活动完成后正式扣除";
        public static final int POINTS = 1500;
    }

    // ==================== 文章置顶积分扣减 ====================
    public static class ArticleTop {
        public static final String SOURCE_TYPE = "articleTop";
        public static final String SUBJECT = "新闻首页置顶推荐";
        public static final String SUBJECT_DESC_TEMPLATE = "新闻：%s";
        public static final String REASON_TEMPLATE = "兑换成功，新闻置顶展示至 %s";
        public static final int POINTS = 500;
    }

    // ==================== 项目置顶积分扣减 ====================
    public static class ProjectTop {
        public static final String SOURCE_TYPE = "projectTop";
        public static final String SUBJECT = "项目首页置顶推荐";
        public static final String SUBJECT_DESC_TEMPLATE = "项目：%s";
        public static final String REASON_TEMPLATE = "兑换成功，项目置顶展示至 %s";
        public static final int POINTS = 800;
    }

    // ==================== 发布项目审核通过 ====================
    public static class PublishProject {
        public static final String SOURCE_TYPE = "publishProject";
        public static final String SUBJECT = "关联项目";
        public static final String SUBJECT_DESC_TEMPLATE = "项目：%s";
        public static final String REASON = "个人项目成功关联，奖励 10 分已到账";
        public static final int POINTS = 10;
    }

    // ==================== 专家一对一答疑预约冻结 ====================
    public static class ExpertQA {
        public static final String SOURCE_TYPE = "expertQaFreeze";
        public static final String SUBJECT = "专家一对一答疑（预约冻结）";
        public static final String REASON = "申请审核中，答疑完成后正式扣除";
        public static final int POINTS = 4000;
    }


    /**
     * 资源审核状态-审核通过
     */
    public final static String RESOURCE_AUDIT_PASS = "1";
    /**
     * 资源审核状态-审核未通过
     */
    public final static String RESOURCE_AUDIT_FAILED = "2";
    /**
     * 资源审核状态-待审核
     */
    public final static String RESOURCE_NOT_AUDIT = "0";

    /**
     * 项目审核状态-审核通过
     */
    public final static String PROJECT_AUDIT_PASS = "1";
    /**
     * 项目审核状态-审核未通过
     */
    public final static String PROJECT_AUDIT_FAILED = "2";
    /**
     * 项目审核状态-待审核
     */
    public final static String PROJECT_NOT_AUDIT = "0";
    /**
     * 前台权限-管理者
     */
    public final static String FRONT_ROLE_MANAGER = "Manager";
    /**
     * 前台权限-会员
     */
    public final static String FRONT_ROLE_MEMBER = "Member";
    /**
     * 前台权限-无权限
     */
    public final static String FRONT_ROLE_NONE = "None";

    public static String getFileSuffixOfResourceTypeRedisKey(Long zoneId, String fileSuffix) {
        return REDIS_KEY_FILE_SUFFIX_OF_RESOURCE_TYPE_PREFIX + zoneId + "_" + fileSuffix;
    }
}
