package com.spot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.HeaderHttpSessionIdResolver;
import org.springframework.session.web.http.HttpSessionIdResolver;

/**
 * Redis Session 配置，与 dage 共享同一 Redis 中的 Session
 * Session ID 通过请求头 x-auth-token 传递，与 dage SmartHttpSessionStrategy 保持一致
 * maxInactiveIntervalInSeconds 与 dage HttpSessionConfig 保持相同（864000秒=10天）
 *
 * @author jean
 * @date 2026-05-09
 */
@Configuration
@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 864000)
public class HttpSessionConfig {

    /**
     * 从请求头 x-auth-token 中读取 Session ID，与 dage 的 HeaderHttpSessionStrategy 一致
     *
     * @return Session ID 解析器
     */
    @Bean
    public HttpSessionIdResolver httpSessionIdResolver() {
        return HeaderHttpSessionIdResolver.xAuthToken();
    }
}
