package com.m2pool.common.security.config;

import com.m2pool.common.security.interceptor.CoinInterceptor;
import com.m2pool.common.security.interceptor.HeaderInterceptor;
import com.m2pool.common.security.interceptor.OpenApiHeaderInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description 拦截器配置
 * @Date 2024/6/13 19:56
 * @Author dy
 */
public class WebMvcConfig implements WebMvcConfigurer {

    /** token 不需要拦截的地址 */
    public static final String[] excludeUrls = {"/login","/logout","/refresh",
            "/account/hashrate_real","/account/hashrate_history","/account/hashrate_last24h",
            "/account/miners_list","/account/watch","/account/test1",
            "/miner/hashrate_real","/miner/hashrate_history","/miner/hashrate_last24h",
            "/pool/hashrate","/pool/hashrate_history","/pool/miners_list","/pool/watch","/oapi/**"};

    public static final String[] matchUrls = {
            "/account/hashrate_real","/account/hashrate_history","/account/hashrate_last24h",
            "/account/miners_list","/account/watch","/account/test1",
            "/miner/hashrate_real","/miner/hashrate_history","/miner/hashrate_last24h",
            "/pool/hashrate","/pool/hashrate_history","/pool/miners_list","/pool/watch","/oapi/**"};

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getHeaderInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(excludeUrls)
                .order(-10);

        registry.addInterceptor(getOpenApiHeaderInterceptor())
                .addPathPatterns(matchUrls)
                .excludePathPatterns("/auth/**,/system/**,/pool/**")
                .order(-15);

        //registry.addInterceptor(getCoinInterceptor())
        //        .addPathPatterns("/**")
        //        .order(-20);

    }
    /**
     * 自定义请求头拦截器
     */
    public HeaderInterceptor getHeaderInterceptor(){return new HeaderInterceptor();}

    public OpenApiHeaderInterceptor getOpenApiHeaderInterceptor(){return new OpenApiHeaderInterceptor();}

    public CoinInterceptor getCoinInterceptor(){return new CoinInterceptor();}
}
