package com.xindazhou.gateway.config;

import com.xindazhou.gateway.core.jwt.GatewayJwtUtil;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;

/**
 * Gateway JWT 配置
 * 初始化 JWT 工具类，用于验证 Token
 *
 * @author xindazhou
 */
@Slf4j
@Configuration
public class GatewayJwtConfiguration {

    @Value("${xdz.security.oauth2-jwt.public-key-path:}")
    private String publicKeyPath;

    private final ResourceLoader resourceLoader;

    public GatewayJwtConfiguration(ResourceLoader resourceLoader) {
        this.resourceLoader = resourceLoader;
    }

    @PostConstruct
    public void init() {
        // Gateway 只需要公钥验证 Token，不需要私钥
        GatewayJwtUtil.init(publicKeyPath, resourceLoader);
        log.info("Gateway JWT 初始化完成: publicKeyPath={}", publicKeyPath);
    }
}

