package ink.wgink.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: ServerProperties
 * @Description: 服务配置
 * @Author: WangGeng
 * @Date: 2019/9/3 10:14 上午
 * @Version: 1.0
 **/
@Component
@ConfigurationProperties(prefix = "server")
public class ServerProperties {

    /**
     * 服务端口
     */
    private Integer port;
    /**
     * 访问地址
     */
    private String url;
    /**
     * WebSocket 地址
     */
    private String ws;
    /**
     * 系统主标题
     */
    private String systemTitle;
    /**
     * 系统副标题
     */
    private String systemSubTitle;
    /**
     * 默认 index 页面
     */
    private String defaultIndexPage;
    /**
     * 默认 home 页面
     */
    private String defaultHomePage;
    /**
     * 初始化
     */
    private ServerInitProperties init;
    /**
     * 主节点
     */
    private Boolean masterNode;

    public Integer getPort() {
        return port;
    }

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

    public String getUrl() {
        return url == null ? "" : url.trim();
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getWs() {
        return ws == null ? "" : ws.trim();
    }

    public void setWs(String ws) {
        this.ws = ws;
    }

    public String getSystemTitle() {
        return systemTitle == null ? "统一用户管理系统" : systemTitle.trim();
    }

    public void setSystemTitle(String systemTitle) {
        this.systemTitle = systemTitle;
    }

    public String getSystemSubTitle() {
        return systemSubTitle == null ? "山西腾狮科技" : systemSubTitle.trim();
    }

    public void setSystemSubTitle(String systemSubTitle) {
        this.systemSubTitle = systemSubTitle;
    }

    public String getDefaultIndexPage() {
        return defaultIndexPage == null ? "" : defaultIndexPage;
    }

    public void setDefaultIndexPage(String defaultIndexPage) {
        this.defaultIndexPage = defaultIndexPage;
    }

    public String getDefaultHomePage() {
        return defaultHomePage == null ? "" : defaultHomePage.trim();
    }

    public void setDefaultHomePage(String defaultHomePage) {
        this.defaultHomePage = defaultHomePage;
    }

    public ServerInitProperties getInit() {
        return init;
    }

    public void setInit(ServerInitProperties init) {
        this.init = init;
    }

    public Boolean getMasterNode() {
        return masterNode == null ? false : masterNode;
    }

    public void setMasterNode(Boolean masterNode) {
        this.masterNode = masterNode;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"port\":")
                .append(port);
        sb.append(",\"url\":\"")
                .append(url).append('\"');
        sb.append(",\"ws\":\"")
                .append(ws).append('\"');
        sb.append(",\"systemTitle\":\"")
                .append(systemTitle).append('\"');
        sb.append(",\"systemSubTitle\":\"")
                .append(systemSubTitle).append('\"');
        sb.append(",\"defaultIndexPage\":\"")
                .append(defaultIndexPage).append('\"');
        sb.append(",\"defaultHomePage\":\"")
                .append(defaultHomePage).append('\"');
        sb.append(",\"init\":")
                .append(init);
        sb.append(",\"masterNode\":")
                .append(masterNode);
        sb.append('}');
        return sb.toString();
    }
}
