"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const command_1 = require("@oclif/command");
const env_1 = require("../utils/env");
const command_2 = __importDefault(require("../extends/command"));
const account_1 = __importDefault(require("../implements/account"));
class Switch extends command_2.default {
    async run() {
        const { flags } = await this.parse(Switch);
        const account = new account_1.default();
        account.eventTracker('switch_start', { tags: Object.assign({}, flags) });
        account_1.default.checkTokenExist(this.id);
        const switchEnv = Object.keys(flags).includes('environment');
        const switchTenant = Object.keys(flags).includes('tenant');
        if (switchEnv) {
            await account.switchEnv({
                environment: flags.environment,
            });
        }
        else if (switchTenant) {
            await account.switchTenant();
        }
        else {
            await account.switchEnv({});
            await account.switchTenant();
        }
        console.info(this.success('Success') + ' switched, current user is: ', account.getUserInfo());
    }
}
exports.default = Switch;
Switch.description = 'Switch identity';
Switch.flags = {
    environment: command_1.flags.string({
        char: 'e',
        description: 'switch env',
        options: [...env_1.environment],
    }),
    tenant: command_1.flags.boolean({
        char: 't',
        description: 'switch tenant',
    }),
    help: command_1.flags.help({
        char: 'h',
    }),
};
Switch.examples = [['$ {{cli}} env switch feishu', 'switch env to feishu']];
