"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const cliConfigProvider_1 = require("@mablhq-internal/runtime/providers/cliConfigProvider");
const set_1 = require("./set");
const configKeys_1 = require("@mablhq-internal/runtime/providers/configKeys");
const cli_table3_1 = __importDefault(require("cli-table3"));
const list_1 = require("./list");
const loggingProvider_1 = require("@mablhq-internal/runtime/providers/logging/loggingProvider");
exports.command = `get <${set_1.configKeyCommandArg}>`;
exports.describe = 'Get a config value';
exports.builder = (yargs) => {
    yargs.positional(set_1.configKeyCommandArg, {
        describe: 'desired configuration key',
        type: 'string',
    });
};
exports.handler = getConfig;
async function getConfig(parsed) {
    const key = parsed['config-key'];
    const table = new cli_table3_1.default({
        head: ['Config', 'Value', 'Details'],
    });
    let value;
    switch (key) {
        case configKeys_1.configKeys.defaultWorkspaceId:
            const workspace = await cliConfigProvider_1.CliConfigProvider.getWorkspace();
            if (workspace) {
                table.push([key, workspace.id, workspace.name]);
                value = workspace.id;
            }
            else {
                table.push([key, list_1.defaultTupleValue, list_1.defaultTupleValue]);
            }
            break;
        default:
            if (!Object.values(configKeys_1.configKeys).includes(key)) {
                throw new Error(`Unknown key [${key}]`);
            }
            const propertyValue = await cliConfigProvider_1.CliConfigProvider.getConfigProperty(key);
            if (propertyValue !== undefined) {
                table.push([key, propertyValue, list_1.defaultTupleValue]);
            }
            else {
                table.push([key, list_1.defaultTupleValue, list_1.defaultTupleValue]);
            }
    }
    loggingProvider_1.logger.info(table.toString());
    return value;
}
