"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const command_base_exec_tenant_1 = require("../command-base-exec-tenant");
const user_context_loader_1 = require("../user-context-loader");
class Logout extends command_base_exec_tenant_1.CommandBaseExecTenant {
    captureArgs() {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            const { flags } = yield this.parse(Logout);
            return [{}, false];
        });
    }
    buildCandidate_silently(_partial, _rootMap) {
        var _a;
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return { userName: (_a = this._userCntx) === null || _a === void 0 ? void 0 : _a.userName };
        });
    }
    buildCandidate_interactively(_partial, _takeDefaults, _rootMap) {
        var _a;
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            return { userName: (_a = this._userCntx) === null || _a === void 0 ? void 0 : _a.userName };
        });
    }
    buildCommandString(_candidate, cmd) {
        cmd.push("--silent");
        return cmd;
    }
    executeTask(candidate) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            if (!candidate.userName) {
                this._ui.userMessage("Nothing to do: user is already logged out.");
                return;
            }
            const userContextLoader = new user_context_loader_1.UserContextLoader(this.cliEnviro, this.logger);
            yield userContextLoader.clearUserContext();
            this._ui.userMessage(`Successfully logged out user ${candidate.userName}.`);
        });
    }
}
exports.default = Logout;
Logout.description = 'Resets the current user to anonymous and clears any local user cache.';
Logout.flags = {
    help: core_1.Flags.help({ char: 'h' }),
    silent: core_1.Flags.boolean({ exclusive: ["echo", "to-script"], description: 'Executes without any user interaction; fails on missing or invalid arguments.' }),
    echo: core_1.Flags.boolean({ exclusive: ["to-script", "silent"], description: 'Renders the equivalent non-interactive command for future use before executing.' }),
    "to-script": core_1.Flags.boolean({ exclusive: ["echo", "silent"], description: 'Renders the equivalent non-interactive command without executing it.' }),
};
Logout.args = {};
Logout.examples = [
    { description: "Log out the current user.", command: "<%= config.bin %> <%= command.id %>" },
    { description: "Non-interactive invocation.", command: "<%= config.bin %> <%= command.id %> --silent" },
    { description: "Renders the equivalent silent command without executing.", command: "<%= config.bin %> <%= command.id %> --to-script" },
];
//# sourceMappingURL=logout.js.map