package com.haha.miniapp.config;

import com.haha.common.config.LogProperties;
import com.haha.common.constant.LogConstants;
import com.haha.common.interceptor.RequestLogInterceptor;
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;

/**
 * Web MVC 配置类
 * 用于配置拦截器、跨域、静态资源等
 *
 * @author haha
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final RequestLogInterceptor requestLogInterceptor;

    private final LogProperties logProperties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册请求日志拦截器
        if (logProperties.getEnableRequestLog()) {
            registry.addInterceptor(requestLogInterceptor)
                    .addPathPatterns("/**")
                    .excludePathPatterns(LogConstants.EXCLUDE_PATHS);
        }
    }
}
