package com.qmth.boot.core.cache.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 + ".cache")
@Validated
public class CacheProperties {

    private boolean allowNullValue = true;

    @NotNull
    @DurationMin(seconds = 0)
    private Duration expireAfterWrite = Duration.ofSeconds(0);

    public boolean isAllowNullValue() {
        return allowNullValue;
    }

    public void setAllowNullValue(boolean allowNullValue) {
        this.allowNullValue = allowNullValue;
    }

    public Duration getExpireAfterWrite() {
        return expireAfterWrite;
    }

    public void setExpireAfterWrite(Duration expireAfterWrite) {
        this.expireAfterWrite = expireAfterWrite;
    }
}
