package itn.com.cmm.session;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;

@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 1800) // 세션 timeout 설정
public class HttpSessionConfig {
	
	@Value("#{globalSettings['Globals.valkey.ip']}")
	private String ip;
	
	@Value("#{globalSettings['Globals.valkey.port']}")
	private int port;
	
	@Value("#{globalSettings['Globals.valkey.password']}")
	private String password;

	@Bean
	public JedisConnectionFactory connectionFactory() {
	    JedisConnectionFactory factory = new JedisConnectionFactory();
	    factory.setHostName(this.ip);
	    factory.setPort(this.port);
	    factory.setPassword(this.password);
	    factory.afterPropertiesSet();
	    return factory;
	}

    @Bean
    public RedisTemplate<Object, Object> redisTemplate() {
        RedisTemplate<Object, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(connectionFactory());
        return template;
    }
}
