package com.cm.central.control.config.properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: CentralControlSocketServerConfig
 * @Description: 中控socket配置
 * @Author: WangGeng
 * @Date: 2020/7/28 1:48 下午
 * @Version: 1.0
 **/
@Component
@ConfigurationProperties(prefix = "socket.central-control.server")
public class SocketServerProperties {

    private Integer port = 9999;
    private Integer soBacklog = 1024;
    private Integer readIdleTimeSecond = 5;
    private Integer offlineNoticeMinute = 10;
    private String offlineNoticeType = "email";
    private Integer offlineNoticeCount = 3;
    private Integer exceptionNoticeCount;

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public Integer getSoBacklog() {
        return soBacklog;
    }

    public void setSoBacklog(Integer soBacklog) {
        this.soBacklog = soBacklog;
    }

    public Integer getReadIdleTimeSecond() {
        return readIdleTimeSecond < 5 ? 5 : readIdleTimeSecond;
    }

    public void setReadIdleTimeSecond(Integer readIdleTimeSecond) {
        this.readIdleTimeSecond = readIdleTimeSecond;
    }

    public Integer getOfflineNoticeMinute() {
        return offlineNoticeMinute == null || offlineNoticeMinute < 1 ? 10 : offlineNoticeMinute;
    }

    public void setOfflineNoticeMinute(Integer offlineNoticeMinute) {
        this.offlineNoticeMinute = offlineNoticeMinute;
    }

    public String getOfflineNoticeType() {
        return offlineNoticeType == null ? "" : offlineNoticeType.trim();
    }

    public void setOfflineNoticeType(String offlineNoticeType) {
        this.offlineNoticeType = offlineNoticeType;
    }

    public Integer getOfflineNoticeCount() {
        return offlineNoticeCount == null || offlineNoticeCount < 3 ? 3 : offlineNoticeCount;
    }

    public void setOfflineNoticeCount(Integer offlineNoticeCount) {
        this.offlineNoticeCount = offlineNoticeCount;
    }

    public Integer getExceptionNoticeCount() {
        return exceptionNoticeCount == null || exceptionNoticeCount < 10 ? 10 : exceptionNoticeCount;
    }

    public void setExceptionNoticeCount(Integer exceptionNoticeCount) {
        this.exceptionNoticeCount = exceptionNoticeCount;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"port\":")
                .append(port);
        sb.append(",\"soBacklog\":")
                .append(soBacklog);
        sb.append(",\"readIdleTimeSecond\":")
                .append(readIdleTimeSecond);
        sb.append(",\"offlineNoticeMinute\":")
                .append(offlineNoticeMinute);
        sb.append(",\"offlineNoticeType\":")
                .append("\"").append(offlineNoticeType).append("\"");
        sb.append(",\"offlineNoticeCount\":")
                .append(offlineNoticeCount);
        sb.append(",\"exceptionNoticeCount\":")
                .append(exceptionNoticeCount);
        sb.append('}');
        return sb.toString();
    }
}
