package com.lion.lionwebsite.Configuration;

import com.lion.lionwebsite.Domain.MaskDomain;
import com.lion.lionwebsite.Interceptor.HumanInterceptor;
import com.lion.lionwebsite.Interceptor.PersonalInterceptor;
import com.lion.lionwebsite.Interceptor.TaskHandlerInterceptor;
import com.lion.lionwebsite.Util.CustomUtil;
import jakarta.annotation.Resource;
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 {
    @Resource
    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();
    }

    @Bean
    public CustomUtil getParameterUtil(){
        CustomUtil customUtil = new CustomUtil();
        MaskDomain[] maskDomains = new MaskDomain[2];
        maskDomains[0] = new MaskDomain("exhentai.org", "element-plus.org");
        maskDomains[1] = new MaskDomain("e-hentai.org", "element.org");
        customUtil.setMaskDomains(maskDomains);
        return customUtil;
    }
}
