package com.sonic.pigeon.utils;

import com.sonic.common.AppRuntime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 统一的 redis key 管理工具类（方便后续的维护和查找）
 *
 * @Author code
 * @Date 2021/9/24
 * @Version 1.0
 */
@Slf4j
@Service
public class RedisKeyUtils {

    @Value("${spring.profiles.active}")
    private String runMode;
    @Autowired
    private AppRuntime appRuntime;

    /**
     * 反馈上锁
     *
     * @return
     */
    public String feedbackLockKey(Long userId) {
        return appRuntime.buildPrefixKey("lock", "feedback", userId);
    }

    /**
     * 反馈限流
     *
     * @return
     */
    public String feedbackLimitKey(Long userId) {
        return appRuntime.buildPrefixKey("limit", "feedbackV2", userId);
    }

    /**
     * 消息统计锁
     *
     * @return
     */
    public String messageStatLockKey(Long userId) {
        return appRuntime.buildPrefixKey("lock", "messageStat", userId);
    }


    /**
     * 关系等级缓存
     * @param userId
     * @param aiId
     * @return
     */
    public String aiUserHeartbeatLevelCacheKey(Long userId, Long aiId) {
        if("test".equalsIgnoreCase(runMode)) {
            return "1002:test:cache:heartbeatLevel:" + userId + ":" + aiId;
        }
        return "1002:cache:heartbeatLevel:" + userId + ":" + aiId;
    }

}
