package com.stdproject.config;

import cn.hutool.cache.Cache;
import cn.hutool.cache.CacheUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 *
 * @author StdProject
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${spring.security.jwt.expiration-ms}")
    private Long expirationMs;

    /**
     * 用户缓存
     */
    @Bean
    public Cache<String, String> loginuserCache() {
        return CacheUtil.newTimedCache(expirationMs);
    }

    /**
     * 静态资源处理
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // Swagger UI 静态资源
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/");

        // 其他静态资源
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
}
