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

import com.qmth.boot.core.constant.CoreConstant;
import com.qmth.boot.core.logger.constant.LoggerConstant;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.util.unit.DataSize;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Component
@ConfigurationProperties(prefix = CoreConstant.CONFIG_PREFIX + ".logging")
@Validated
public class LoggerProperties implements LoggerConstant {

    @NotBlank
    private String pattern = DEFAULT_PATTERN;

    @NotBlank
    private String rootLevel = DEFAULT_LEVEL;

    @Nullable
    private String filePath;

    @NotNull
    private DataSize fileMaxSize = DataSize.ofMegabytes(100);

    @NotNull
    private DataSize totalMaxSize = DataSize.ofGigabytes(20);

    @Min(1)
    private int fileMaxHistory = 7;

    public String getPattern() {
        return pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
    }

    public String getRootLevel() {
        return rootLevel;
    }

    public void setRootLevel(String rootLevel) {
        this.rootLevel = rootLevel;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public DataSize getFileMaxSize() {
        return fileMaxSize;
    }

    public void setFileMaxSize(DataSize fileMaxSize) {
        this.fileMaxSize = fileMaxSize;
    }

    public DataSize getTotalMaxSize() {
        return totalMaxSize;
    }

    public void setTotalMaxSize(DataSize totalMaxSize) {
        this.totalMaxSize = totalMaxSize;
    }

    public int getFileMaxHistory() {
        return fileMaxHistory;
    }

    public void setFileMaxHistory(int fileMaxHistory) {
        this.fileMaxHistory = fileMaxHistory;
    }
}
