package cn.axzo.msg.center.inside.notices.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * @author yanglin
 */
@Setter
@Getter
@RefreshScope
@Configuration
@ConfigurationProperties(prefix = "diagnosis")
public class DiagnosisProps implements EnvironmentAware {

    private Environment environment;
    private RowCount rowCount = new RowCount();

    public String getActiveProfile() {
        String[] profiles = environment.getActiveProfiles();
        return profiles.length > 0 ? profiles[0] : null;
    }

    @Override
    public void setEnvironment(Environment environment) {
        this.environment = environment;
    }

    @Setter
    @Getter
    public static class RowCount {
        private int warningThreshold = 1500;
        private boolean enable  = true;
        private int periodMaxWarnTimes = 2;

        /**
         * For test purpose
         */
        public int determineWarningThreshold() {
            return warningThreshold;
        }
    }

}