package com.qmth.boot.core.security.config;

import com.qmth.boot.core.constant.CoreConstant;
import org.hibernate.validator.constraints.time.DurationMin;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotNull;
import java.time.Duration;

/**
 * 鉴权模块设置参数，支持配置文件自定义修改
 */
@Component
@ConfigurationProperties(prefix = CoreConstant.CONFIG_PREFIX + ".auth")
@Validated
public class SecurityProperties {

    /**
     * 允许服务器时间晚于请求时间戳最大时长，默认180秒
     */
    @NotNull
    @DurationMin(seconds = 1)
    private Duration timeMaxDelay = Duration.ofSeconds(180);

    /**
     * 允许服务器时间早于请求时间戳最大时长，默认30秒
     */
    @NotNull
    @DurationMin(seconds = 0)
    private Duration timeMaxAhead = Duration.ofSeconds(30);

    /**
     * 调试模式，默认不开启；开启后不验证密文直接验证通过
     */
    private boolean debugMode = false;

    public Duration getTimeMaxDelay() {
        return timeMaxDelay;
    }

    public void setTimeMaxDelay(Duration timeMaxDelay) {
        this.timeMaxDelay = timeMaxDelay;
    }

    public Duration getTimeMaxAhead() {
        return timeMaxAhead;
    }

    public void setTimeMaxAhead(Duration timeMaxAhead) {
        this.timeMaxAhead = timeMaxAhead;
    }

    public boolean isDebugMode() {
        return debugMode;
    }

    public void setDebugMode(boolean debugMode) {
        this.debugMode = debugMode;
    }
}
