package top.continew.admin.config.filter;

import lombok.RequiredArgsConstructor;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;

/**
 * 过滤器配置类
 *
 * @author jiay
 * @since 2025/08/28 00:00
 */
@Configuration
@RequiredArgsConstructor
public class FilterConfiguration {

    private final ThirdPartyTokenFilter thirdPartyTokenFilter;

    /**
     * 注册第三方平台Token校验过滤器
     */
    @Bean
    public FilterRegistrationBean<ThirdPartyTokenFilter> thirdPartyTokenFilterRegistration() {
        FilterRegistrationBean<ThirdPartyTokenFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(thirdPartyTokenFilter);
        registration.addUrlPatterns("/billing/*"); // 只对计费接口生效
        registration.setName("ThirdPartyTokenFilter");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 10);
        return registration;
    }
}