package com.njyunzhi.pet_identity.config;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.jwt.StpLogicJwtForStateless;
import cn.dev33.satoken.stp.StpLogic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {
    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> anonList = new ArrayList<>();
        anonList.add("/swagger-ui/**");
        anonList.add("/swagger-resources/**");
        anonList.add("/v2/**");
        anonList.add("/wxpay/notify/**");
        anonList.add("/h5/**");
        anonList.add("/**/sms-captcha");
        anonList.add("/**/**/sms-captcha");
        anonList.add("/**/preload");
        anonList.add("/**/login");
        anonList.add("/**/**/login");

        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(new SaRouteInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns(anonList.toArray(new String[0]));
    }



    // Sa-Token 整合 jwt (Style模式)
    @Bean
    public StpLogic getStpLogicJwt() {
        return new StpLogicJwtForStateless();
    }
}
