import {Context} from "./Context";
import * as os from 'os'

/**
 * 当前node 用到的环境变量名称
 */
export class EnvVariables {

    private static KT_UTS_CRON = 'KT_UTS_CRON';
    private static KT_UTS_TASK_TYPE = 'KT_UTS_TASK_TYPE';
    private static KT_UTS_EXECUTOR = 'KT_UTS_EXECUTOR';
    private static KT_BS_REGISTER_URL = 'KT_BS_REGISTER_URL';
    private static KT_K8S_ID = 'KT_K8S_ID';
    private static KT_DISABLED_HEARTBEAT_TASK = 'KT_DISABLED_HEARTBEAT_TASK';
    private static KT_DEPLOY_ID = 'KT_DEPLOY_ID';
    private static KT_DEPLOY_TIME = 'KT_DEPLOY_TIME';
    private static KT_ME_ENV = 'KT_ME_ENV';
    private static KT_ME_ENV_KEY = 'KT_ME_ENV_KEY';
    private static KT_POD_MIN_INSTANCE = 'KT_POD_MIN_INSTANCE';
    private static KT_UTS_DBLOCK_HOST = 'KT_UTS_DBLOCK_HOST';
    private static KT_UTS_DBLOCK_USER = 'KT_UTS_DBLOCK_USER';
    private static KT_UTS_DBLOCK_PASSWORD = 'KT_UTS_DBLOCK_PASSWORD';
    private static KT_UTS_DBLOCK_DATABASE = 'KT_UTS_DBLOCK_DATABASE';
    private static KT_UTS_DBLOCK_PORT = 'KT_UTS_DBLOCK_PORT';
    private static NODE_HTTP_PORT = 'NODE_HTTP_PORT';
    private static NODE_HTTP_CONTEXT_PATH = 'NODE_HTTP_CONTEXT_PATH';
    private static NODE_ENV = 'NODE_ENV';
    private static KT_EC_TOPIC = 'KT_EC_TOPIC';
    private static KT_HEARTBEAT_SERVICE_URL = 'KT_HEARTBEAT_SERVICE_URL';

    /**
     * 获取心跳上报地址
     */
    static getHeartbeatServiceUrl(): string {
        return Context.getEnv(this.KT_HEARTBEAT_SERVICE_URL)
    }

    /**
     * 获取主注册中心服务地址地址
     * @return https://xxxx.bbb.ccc/master
     */
    static getMasterRegisterUrl(): string {
        return Context.getEnv(this.KT_BS_REGISTER_URL)
    }

    /**
     * 获取K8S容器ID
     * @return uuid
     */
    static getK8SId(): string {
        return Context.getEnv(this.KT_K8S_ID)
    }

    /**
     * 是否禁用心跳上报任务
     * @return uuid
     */
    static isDisabledHeartbeatTask(): boolean {
        return Context.getEnv(this.KT_DISABLED_HEARTBEAT_TASK) === 'true'
    }

    /**
     * 获取部署配置ID
     * @return uuid
     */
    static getDeployId(): string {
        return Context.getEnv(this.KT_DEPLOY_ID)
    }

    /**
     * 获取部署时间
     * @return yyyy-MM-dd HH:mm:ss
     */
    static getDeployTime(): string {
        return Context.getEnv(this.KT_DEPLOY_TIME)
    }

    /**
     * 获取环境变量代码
     * @return uuid
     */
    static getEnvCode(): string {
        return Context.getEnv(this.KT_ME_ENV)
    }

    /**
     * 获取环境变量签名秘钥
     * @return uuid
     */
    static getEnvKey(): string {
        return Context.getEnv(this.KT_ME_ENV_KEY)
    }

    /**
     * 获取POD ID
     * @return uuid
     */
    static getPodId(): string {
        return os.hostname()
    }

    /**
     * 获取Node端口号
     * @return uuid
     */
    static getNodeHttpPort(): string {
        return Context.getEnv(this.NODE_HTTP_PORT)
    }


    /**
     * 获取Node上下文路径
     * @return uuid
     */
    static getNodeHttpContextPath(): string {
        return Context.getEnv(this.NODE_HTTP_CONTEXT_PATH) || ''
    }

    /**
     * 获取Node运行环境代码
     * @return DEBUG || DEV || TEST || PROD
     */
    static getNodeEnv(): string {
        return Context.getEnv(this.NODE_ENV) + ''.toUpperCase()
    }

    /**
     * 获取 UTS定时任务 CRON表达式
     * @return 0 10/0 * * * *
     */
    static getUTSCron(): string {
        return Context.getEnv(this.KT_UTS_CRON)
    }

    /**
     * 获取 UTS 执行人姓名
     * @return 张三
     */
    static getUTSExecutor(): string {
        return Context.getEnv(this.KT_UTS_EXECUTOR)
    }

    /**
     * 获取 UTS 任务类型
     * @return 0 长开，1 非长开，2 :立即执行
     */
    static getUTSTaskType(): string {
        return Context.getEnv(this.KT_UTS_TASK_TYPE)
    }

    /**
     * 获取pod最小实例
     * @return
     */
    static getPodMinInstance(): string {
        return Context.getEnv(this.KT_POD_MIN_INSTANCE) || ''
    }

    /**
     * 获取uts dblock host
     */
    static getUTSDblockHost(): string {
        return Context.getEnv(this.KT_UTS_DBLOCK_HOST)
    }

    /**
     * 获取uts dblock user
     */
    static getUTSDblockUser(): string {
        return Context.getEnv(this.KT_UTS_DBLOCK_USER)
    }

    /**
     * 获取uts dblock password
     */
    static getUTSDblockPassword(): string {
        return Context.getEnv(this.KT_UTS_DBLOCK_PASSWORD)
    }

    /**
     * 获取uts dblock database
     */
    static getUTSDblockDatabase(): string {
        return Context.getEnv(this.KT_UTS_DBLOCK_DATABASE)
    }

    /**
     * 获取uts dblock port
     */
    static getUTSDblockPort(): string {
        return Context.getEnv(this.KT_UTS_DBLOCK_PORT)
    }

    /**
     * 获取 事件topic
     * @return
     */
    static getEcTopic(): string {
        return Context.getEnv(this.KT_EC_TOPIC)
    }
}