package com.platform.modules.app.config;

import java.util.List;

import com.platform.modules.foreign.oauth2.ForeignOAuth2Interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.platform.modules.app.interceptor.AuthorizationInterceptor;
import com.platform.modules.app.resolver.LoginUserHandlerMethodArgumentResolver;
import com.platform.modules.qk.interceptor.CloudClipsAuthorizationInterceptor;

/**
 * MVC配置
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;
    @Autowired
    private LoginUserHandlerMethodArgumentResolver loginUserHandlerMethodArgumentResolver;
    @Autowired
    private CloudClipsAuthorizationInterceptor qukanAuthorizationInterceptor;
    @Autowired
    private ForeignOAuth2Interceptor foreignOAuth2Interceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authorizationInterceptor).addPathPatterns("/app/**");
        registry.addInterceptor(qukanAuthorizationInterceptor).addPathPatterns("/api/cloud/clips/**");
        // TODO 20190228 TROY 暂时只拦截列表，详情页数据需要公开，无法鉴权
        registry.addInterceptor(foreignOAuth2Interceptor).addPathPatterns("/foreign/live/scene/list")
                .addPathPatterns("/foreign/live/channel/list").addPathPatterns("/foreign/live/reporter/list").addPathPatterns("/foreign/live/task/allocation");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(loginUserHandlerMethodArgumentResolver);
    }
}