package org.lingniu.idp.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.time.Duration;

@Component
@ConfigurationProperties(prefix = "idp.jwt")
public class JwtProperties {
    
    // 令牌配置
    private String header = "Authorization";
    private String prefix = "Bearer ";
    private Duration expiration = Duration.ofHours(1);
    private Duration refreshExpiration = Duration.ofDays(7);
    
    // RSA 密钥配置（支持文件路径或直接内容）
    private RsaKey rsa = new RsaKey();
    
    // RSA 密钥内部类
    @Setter
    @Getter
    public static class RsaKey {
        // Getter 和 Setter
        /**
         * 私钥路径或内容（用于签名）
         * 优先级：content > location
         */
        private String privateKey;
        
        /**
         * 公钥路径或内容（用于验证）
         * 优先级：content > location
         */
        private String publicKey;
        
        /**
         * 密钥算法，默认 RSA
         */
        private String algorithm = "RSA";
        
        /**
         * 密钥长度，默认 2048
         */
        private int keySize = 2048;

    }
    
    // Getter 和 Setter（原有）
    public String getHeader() { return header; }
    public void setHeader(String header) { this.header = header; }
    
    public String getPrefix() { return prefix; }
    public void setPrefix(String prefix) { this.prefix = prefix; }
    
    public Duration getExpiration() { return expiration; }
    public void setExpiration(Duration expiration) { this.expiration = expiration; }
    
    public Duration getRefreshExpiration() { return refreshExpiration; }
    public void setRefreshExpiration(Duration refreshExpiration) { this.refreshExpiration = refreshExpiration; }
    
    // RSA 配置 Getter 和 Setter
    public RsaKey getRsa() { return rsa; }
    public void setRsa(RsaKey rsa) { this.rsa = rsa; }
}