package com.qmth.jkserver.core.config;

import com.qmth.jkserver.core.inteceptor.ApiInterceptor;
import com.qmth.jkserver.core.inteceptor.SystemInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器 配置
 *
 * @author tianjun
 */
@Configuration
public class WebInteceptorConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/system/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "POST")
                .allowCredentials(false).maxAge(3600);
    }
//
//	@Override
//	public void addInterceptors(InterceptorRegistry registry) {
//		registry.addInterceptor(new ApiInterceptor()).addPathPatterns("/api/**");
//		registry.addInterceptor(new SystemInterceptor()).addPathPatterns("/system/**");
//	}

    @Bean
    public ApiInterceptor ApiInterceptor() {
        return new ApiInterceptor();
    }

    @Bean
    public SystemInterceptor SystemInterceptor() {
        return new SystemInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(ApiInterceptor()).addPathPatterns("/api/**");
        registry.addInterceptor(SystemInterceptor()).addPathPatterns("/system/**");
    }

//    @Bean
//    InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor, PrometheusMeterRegistry registry) {
//        return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
//    }

//    @Bean
//    InitializingBean forcePrometheusPostProcessor(BeanPostProcessor meterRegistryPostProcessor, SimpleMeterRegistry registry) {
//        return () -> meterRegistryPostProcessor.postProcessAfterInitialization(registry, "");
//    }
}
