"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultsOnlyConfigurationService = void 0;
const configurationService_1 = require("./configurationService");
/** Provides only the default values, ignoring the user's settings or exp. */
class DefaultsOnlyConfigurationService extends configurationService_1.AbstractConfigurationService {
    getConfig(key) {
        return this.getDefaultValue(key);
    }
    inspectConfig(key, scope) {
        return {
            defaultValue: this.getDefaultValue(key),
        };
    }
    setConfig(key, value, _target) {
        return Promise.resolve();
    }
    getNonExtensionConfig(configKey) {
        return undefined;
    }
    getExperimentBasedConfig(key, experimentationService, scope) {
        if (key.experimentName) {
            const expValue = experimentationService.getTreatmentVariable(key.experimentName);
            if (expValue !== undefined) {
                return expValue;
            }
        }
        // This is the pattern we've been using for a while now. We need to maintain it for older experiments.
        const expValue = experimentationService.getTreatmentVariable(`copilotchat.config.${key.id}`);
        if (expValue !== undefined) {
            return expValue;
        }
        // This is the pattern vscode uses for settings using the `onExp` tag. But vscode only supports it for
        // settings defined in package.json, so this is why we're also reading the value from exp here.
        const expValue2 = experimentationService.getTreatmentVariable(`config.${key.fullyQualifiedId}`);
        if (expValue2 !== undefined) {
            return expValue2;
        }
        if (key.fullyQualifiedOldId) {
            const oldExpValue = experimentationService.getTreatmentVariable(`copilotchat.config.${key.oldId}`);
            if (oldExpValue !== undefined) {
                return oldExpValue;
            }
            const oldExpValue2 = experimentationService.getTreatmentVariable(`config.${key.fullyQualifiedOldId}`);
            if (oldExpValue2 !== undefined) {
                return oldExpValue2;
            }
        }
        return this.getDefaultValue(key);
    }
    updateExperimentBasedConfiguration(treatments) {
        if (treatments.length === 0) {
            return;
        }
        // Fire simulated event which checks if a configuration is affected in the treatments
        this._onDidChangeConfiguration.fire({
            affectsConfiguration: (section, _scope) => {
                if (treatments.some(t => t.startsWith(`config.${section}`))) {
                    return true;
                }
                const oldId = configurationService_1.globalConfigRegistry.configs.get(section)?.fullyQualifiedOldId;
                if (oldId && treatments.some(t => t.startsWith(`config.${oldId}`))) {
                    return true;
                }
                return false;
            }
        });
    }
    dumpConfig() {
        return {};
    }
}
exports.DefaultsOnlyConfigurationService = DefaultsOnlyConfigurationService;
//# sourceMappingURL=defaultsOnlyConfigurationService.js.map