package com.kingdee.eas.custom.integration.base.config;

import com.kingdee.eas.custom.integration.base.exception.CommonErrorCodes;
import com.kingdee.eas.custom.integration.base.exception.IntegrationException;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 公共基础设施配置
 */
public class CommonConfig {

    private String dataCenter;
    private String locale;
    private String mobileBosUrl;
    private String shrServerName;

    public CommonConfig() {
    }

    public CommonConfig(Map<String, String> common) {
        this.dataCenter = common.get("dataCenter");
        this.locale = common.getOrDefault("locale", "L2");
        this.mobileBosUrl = common.getOrDefault("mobileBosUrl", "https://mbos.kdeascloud.com/");
        this.shrServerName = common.get("shrServerName");
    }

    public String getDataCenter() {
        if (StringUtils.isBlank(dataCenter)) {
            throw new IntegrationException(CommonErrorCodes.PARAM_MISSING, "dataCenter is blank");
        }
        return dataCenter;
    }

    public void setDataCenter(String dataCenter) {
        this.dataCenter = dataCenter;
    }

    public String getLocale() {
        return locale;
    }

    public void setLocale(String locale) {
        this.locale = locale;
    }

    public String getMobileBosUrl() {
        return mobileBosUrl;
    }

    public void setMobileBosUrl(String mobileBosUrl) {
        this.mobileBosUrl = mobileBosUrl;
    }

    public String getShrServerName() {
        if (StringUtils.isBlank(shrServerName)) {
            throw new IntegrationException(CommonErrorCodes.PARAM_MISSING, "shrServerName is blank");
        }
        return shrServerName;
    }

    public void setShrServerName(String shrServerName) {
        this.shrServerName = shrServerName;
    }

    @Override
    public String toString() {
        return "CommonConfig{dataCenter='" + dataCenter + "', locale='" + locale +
                "', mobileBosUrl='" + mobileBosUrl + "', shrServerName='" + shrServerName + "'}";
    }
}
