"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const RouteType_1 = require("../enums/RouteType");
const StringUtils_1 = require("../utils/StringUtils");
/**
 * 微服务客户端配置
 * @author WuFengLin
 */
class GatewayConfig {
    constructor() {
        /**
         * 网关服务地址
         */
        this.hostAddress = 'https://mms-service.keytop.cn/';
        /**
         * 微服务应用ID
         */
        this.appId = "";
        /**
         * appId在Header中的变量名称
         */
        this.headerVariableName = "appId";
        /**
         * 微服务 Key
         */
        this.appKey = "";
        /**
         * 环境代码
         */
        this.envCode = "";
        /**
         * 路由类型，默认 GATE_WAY
         */
        this.routeType = RouteType_1.RouteType.GATE_WAY;
        this.checkOk = false;
    }
    static make() {
        let result = new GatewayConfig();
        let userId = process.env['KT_ME_USER_ID'] || '';
        let userKey = process.env['KT_ME_USER_KEY'] || '';
        let envCode = process.env['KT_ME_ENV'] || '';
        let envKey = process.env['KT_ME_ENV_KEY'] || '';
        if (StringUtils_1.default.isNotEmpty(userId)) {
            result.appId = userId;
            result.appKey = userKey;
            result.headerVariableName = 'userId';
            result.envCode = "DEV";
        }
        else if (StringUtils_1.default.isNotEmpty(envCode)) {
            result.appId = envCode;
            result.envCode = envCode;
            result.appKey = envKey;
            result.headerVariableName = 'envCode';
        }
        return result;
    }
    check() {
        if (this.checkOk) {
            return;
        }
        if (StringUtils_1.default.isEmpty(this.hostAddress)) {
            throw new Error("MsClient initialization failed：'hostAddress' Parameter not configured!");
        }
        if (StringUtils_1.default.isEmpty(this.appId)) {
            throw new Error("MsClient initialization failed：'appId' Parameter not configured!");
        }
        if (StringUtils_1.default.isEmpty(this.appKey)) {
            throw new Error("MsClient initialization failed：'appKey' Parameter not configured!");
        }
    }
}
exports.GatewayConfig = GatewayConfig;
//# sourceMappingURL=GatewayConfig.js.map