"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const DefaultClient_1 = require("../http/DefaultClient");
const RouteType_1 = require("../enums/RouteType");
const CommUtils_1 = require("../utils/CommUtils");
const AuthType_1 = require("../enums/AuthType");
class MsConfig {
    constructor() {
        /**
         * 默认网关服务地址
         */
        this.defaultGatewayUrl = 'https://mms-service.keytop.cn/';
        /**
         * 主注册中心地址
         */
        this.masterRegisterUrl = 'https://mms-register-master.keytop.cn/register-master';
        /**
         * 微服务应用ID
         */
        this.appId = "";
        /**
         * appId在Header中的变量名称
         */
        this.headerVariableName = "appId";
        /**
         * 微服务 Key
         */
        this.appKey = "";
        /**
         * 环境代码
         */
        this.envCode = "";
        /**
         * 路由类型，默认 GATE_WAY
         */
        this.routeType = RouteType_1.RouteType.GATE_WAY;
        /**
         * 微服务鉴权方式
         */
        this.authType = AuthType_1.AuthType.BASE;
        this.httpClient = new DefaultClient_1.DefaultClient(this.defaultGatewayUrl);
        if (CommUtils_1.CommUtils.isNodeClient()) {
            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'] || '';
            let masterRegisterUrl = process.env['KT_MMS_REGISTER_MASTER_URL'] || '';
            if (CommUtils_1.CommUtils.isNotEmpty(userId)) {
                this.appId = userId;
                this.appKey = userKey;
                this.headerVariableName = 'userId';
                this.envCode = "DEV";
            }
            else if (CommUtils_1.CommUtils.isNotEmpty(envCode)) {
                this.appId = envCode;
                this.appKey = envKey;
                this.headerVariableName = 'envCode';
            }
            if (CommUtils_1.CommUtils.isNotEmpty(masterRegisterUrl)) {
                this.masterRegisterUrl = masterRegisterUrl;
            }
            this.authType = AuthType_1.AuthType.BASE;
        }
        else {
            //前端直接调中台服务，则不做签名校验
            this.authType = AuthType_1.AuthType.NONE;
        }
    }
}
exports.MsConfig = MsConfig;
exports.default = new MsConfig();
