package com.lion.lionwebsite.Configuration;

import com.lion.lionwebsite.Interceptor.HumanInterceptor;
import com.lion.lionwebsite.Interceptor.PersonalInterceptor;
import com.lion.lionwebsite.Interceptor.TaskHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfiguration implements WebMvcConfigurer {
    TaskHandlerInterceptor taskHandlerInterceptor;

    public InterceptorConfiguration(TaskHandlerInterceptor taskHandlerInterceptor) {
        this.taskHandlerInterceptor = taskHandlerInterceptor;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getPersonalInterceptor()).addPathPatterns("/personal/**", "/remote/**");
        registry.addInterceptor(taskHandlerInterceptor).addPathPatterns("/GalleryManage",  "/validate");
        registry.addInterceptor(getHumanInterceptor()).addPathPatterns("/", "/mobile");
    }

    @Bean
    public HandlerInterceptor getPersonalInterceptor(){
        return new PersonalInterceptor();
    }

    @Bean
    public HandlerInterceptor getHumanInterceptor(){
        return new HumanInterceptor();
    }
}
