"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const stringify = require("json-stringify-safe");
const command_base_enterprise_1 = require("../command-base-enterprise");
class Whoami extends command_base_enterprise_1.CommandBaseEnterprise {
    run() {
        var _a;
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            this.bootstrap();
            const { args, flags } = yield this.parse(Whoami);
            // let userContextRepo = new UserContextLoader(this.logger);
            // let cachedUserContext = userContextRepo.loadUserContext(this._projCfg.tenantCode);
            if (this._userCntx) {
                if (flags.output == "json") {
                    process.stdout.write(stringify(this._userCntx, undefined, 2));
                }
                else { // text
                    this._ui.userMessage(`${this._styler.hilite(this._userCntx.userName)} (tenant: ${this._styler.hilite(this._userCntx.currentTenantCode || "none")})`);
                    if (this._userCntx.roles && (this._userCntx.roles.length > 0)) {
                        this._ui.userMessage(this._styler.dim("└─ roles: ").concat((_a = this._userCntx.roles) === null || _a === void 0 ? void 0 : _a.join(", ")));
                    }
                }
            }
            else {
                if (flags.output == "json") {
                    process.stdout.write("");
                }
                else { // text
                    this._ui.userMessage(`You are not currently logged in.`);
                }
            }
        });
    }
}
exports.default = Whoami;
Whoami.description = 'Renders the codiac username and its current tenant.';
Whoami.aliases = ["user:show"];
Whoami.flags = {
    // help: Flags.help({ char: 'h' }),
    // output: Flags.custom({ char: 'o', options: ['text', 'json'], default: 'text', description: "Format for the response data." })
    output: core_1.Flags.string({ char: 'o', options: ['text', 'json'], default: 'text', description: 'Format for the response data.' }),
};
Whoami.args = {};
//# sourceMappingURL=whoami.js.map