package cn.com.ctop.common.module.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * ADQ 独立 Redis 配置
 * 用于将 ADQ access_token 同步到另一个 Redis 实例
 */
@Configuration
public class AdqRedisConfig {

    /**
     * ADQ 专用 RedisTemplate
     * host：172.30.0.25
     * port：6379
     * password：hcst@2026qwe..
     * db：5
     */
    @Bean(name = "adqRedisTemplate")
    public StringRedisTemplate adqRedisTemplate() {
        RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration();
        standaloneConfig.setHostName("172.30.0.25");
        standaloneConfig.setPort(6379);
        standaloneConfig.setDatabase(5);
        standaloneConfig.setPassword(RedisPassword.of("hcst@2026qwe.."));

        LettuceClientConfiguration clientConfig = LettuceClientConfiguration.builder().build();

        LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(standaloneConfig, clientConfig);
        connectionFactory.afterPropertiesSet();

        StringRedisTemplate template = new StringRedisTemplate(connectionFactory);
        template.afterPropertiesSet();
        return template;
    }
}
