package com.dgtly.apiframework.config;

import com.dgtly.apiframework.interceptor.AuthenticationInterceptor;
import com.dgtly.apiframework.interceptor.VerifyInterceptor;
import com.dgtly.common.config.Global;
import com.dgtly.common.constant.Constants;
import com.dgtly.apiframework.interceptor.ApiRepeatSubmitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 通用配置
 * 
 * @author ruoyi
 */
@Configuration
public class ApiResourcesConfig implements WebMvcConfigurer
{

    @Autowired
    private ApiRepeatSubmitInterceptor apiRepeatSubmitInterceptor;

    /**
     * token验证
     */
    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    /**
     * 接口校验拦截器
     */
    @Autowired
    private VerifyInterceptor verifyInterceptor;



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry)
    {
        /** 本地文件上传路径 */
        registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + Global.getProfile() + "/");

        /** swagger配置 */
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
    }

    /**
     * 自定义拦截规则
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry)
    {
        registry.addInterceptor(apiRepeatSubmitInterceptor).addPathPatterns("/**");
        registry.addInterceptor(authenticationInterceptor).addPathPatterns("/**");
        registry.addInterceptor(verifyInterceptor).addPathPatterns("/**");
    }
}