"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtHostEnv = void 0;
const ide_core_common_1 = require("@opensumi/ide-core-common");
const vscode_1 = require("../../../../common/vscode");
const ext_types_1 = require("../../../../common/vscode/ext-types");
class ExtHostEnv {
    constructor(rpcProtocol) {
        this.logLevelChangeEmitter = new ide_core_common_1.Emitter();
        this.rpcProtocol = rpcProtocol;
        this.proxy = this.rpcProtocol.getProxy(vscode_1.MainThreadAPIIdentifier.MainThreadEnv);
    }
    $setEnvValues(values) {
        return this.setEnvValues(values);
    }
    setEnvValues(values) {
        this.values = Object.assign({}, this.values, values);
    }
    getEnvValues() {
        return this.values;
    }
    async asExternalUri(target) {
        if (!target.scheme.trim().length) {
            throw new Error('Invalid scheme - cannot be empty');
        }
        if (![ide_core_common_1.Schemes.http, ide_core_common_1.Schemes.https, this.values.uriScheme].includes(target.scheme)) {
            throw new Error(`Invalid scheme '${target.scheme}'`);
        }
        const uri = await this.proxy.$asExternalUri(target);
        return ide_core_common_1.URI.revive(uri);
    }
    $fireChangeLogLevel(logLevel) {
        this.$setLogLevel(logLevel);
        this.logLevelChangeEmitter.fire(this.logLevel);
    }
    $setLogLevel(level) {
        this.logLevel = this.toVSCodeLogLevel(level);
    }
    toVSCodeLogLevel(level) {
        if (level === ide_core_common_1.LogLevel.Verbose) {
            return ext_types_1.LogLevel.Trace;
        }
        if (level === ide_core_common_1.LogLevel.Debug) {
            return ext_types_1.LogLevel.Debug;
        }
        if (level === ide_core_common_1.LogLevel.Info) {
            return ext_types_1.LogLevel.Info;
        }
        if (level === ide_core_common_1.LogLevel.Warning) {
            return ext_types_1.LogLevel.Warning;
        }
        if (level === ide_core_common_1.LogLevel.Error) {
            return ext_types_1.LogLevel.Error;
        }
        if (level === ide_core_common_1.LogLevel.Critical) {
            return ext_types_1.LogLevel.Critical;
        }
        if (level === ide_core_common_1.LogLevel.Off) {
            return ext_types_1.LogLevel.Off;
        }
        return ext_types_1.LogLevel.Info;
    }
}
exports.ExtHostEnv = ExtHostEnv;
//# sourceMappingURL=ext.host.env.js.map