package com.lesingle.common.config;

import com.lesingle.common.interceptor.RateLimitInterceptor;
import com.lesingle.common.interceptor.TraceIdInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * WebMvc 配置
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final TraceIdInterceptor traceIdInterceptor;
    private final RateLimitInterceptor rateLimitInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(traceIdInterceptor).addPathPatterns("/**");
        // 速率限制拦截器，仅对公开接口生效
        registry.addInterceptor(rateLimitInterceptor)
                .addPathPatterns("/public/**", "/webhook/**", "/device/**");
    }
}
