"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryHandleRootCommand = exports.ROOT_COMMAND_ROUTES = void 0;
const named_command_router_1 = require("./named-command-router");
async function printUpdateCommandHelp() {
    console.log('');
    console.log('Usage: ccs update [options]');
    console.log('');
    console.log('Options:');
    console.log('  --force       Force reinstall current version');
    console.log('  --beta, --dev Install from dev channel (unstable)');
    console.log('  --help, -h    Show this help message');
    console.log('');
    console.log('Examples:');
    console.log('  ccs update           Update to latest stable');
    console.log('  ccs update --force   Force reinstall');
    console.log('  ccs update --beta    Install dev channel');
    console.log('');
}
exports.ROOT_COMMAND_ROUTES = [
    {
        name: 'migrate',
        aliases: ['--migrate'],
        handle: async (args) => {
            const { handleMigrateCommand, printMigrateHelp } = await Promise.resolve().then(() => __importStar(require('./migrate-command')));
            if (args.includes('--help') || args.includes('-h')) {
                printMigrateHelp();
                return;
            }
            await handleMigrateCommand(args);
        },
    },
    {
        name: 'update',
        aliases: ['--update'],
        handle: async (args) => {
            if (args.includes('--help') || args.includes('-h')) {
                await printUpdateCommandHelp();
                return;
            }
            const { handleUpdateCommand } = await Promise.resolve().then(() => __importStar(require('./update-command')));
            await handleUpdateCommand({
                force: args.includes('--force'),
                beta: args.includes('--beta') || args.includes('--dev'),
            });
        },
    },
    {
        name: 'version',
        aliases: ['--version', '-v'],
        handle: async () => {
            const { handleVersionCommand } = await Promise.resolve().then(() => __importStar(require('./version-command')));
            await handleVersionCommand();
        },
    },
    {
        name: 'help',
        aliases: ['--help', '-h'],
        handle: async (args) => {
            const { handleHelpRoute } = await Promise.resolve().then(() => __importStar(require('./help-command')));
            await handleHelpRoute(args);
        },
    },
    {
        name: '--install',
        handle: async () => {
            const { handleInstallCommand } = await Promise.resolve().then(() => __importStar(require('./install-command')));
            await handleInstallCommand();
        },
    },
    {
        name: '--uninstall',
        handle: async () => {
            const { handleUninstallCommand } = await Promise.resolve().then(() => __importStar(require('./install-command')));
            await handleUninstallCommand();
        },
    },
    {
        name: '--shell-completion',
        aliases: ['-sc'],
        handle: async (args) => {
            const { handleShellCompletionCommand } = await Promise.resolve().then(() => __importStar(require('./shell-completion-command')));
            await handleShellCompletionCommand(args);
        },
    },
    {
        name: '__complete',
        handle: async (args) => {
            const { handleCompletionCommand } = await Promise.resolve().then(() => __importStar(require('./completion-backend')));
            await handleCompletionCommand(args);
        },
    },
    {
        name: 'doctor',
        aliases: ['--doctor'],
        handle: async (args) => {
            const { handleDoctorCommand } = await Promise.resolve().then(() => __importStar(require('./doctor-command')));
            await handleDoctorCommand(args);
        },
    },
    {
        name: 'sync',
        aliases: ['--sync'],
        handle: async () => {
            const { handleSyncCommand } = await Promise.resolve().then(() => __importStar(require('./sync-command')));
            await handleSyncCommand();
        },
    },
    {
        name: 'browser',
        handle: async (args) => {
            const { handleBrowserCommand } = await Promise.resolve().then(() => __importStar(require('./browser-command')));
            await handleBrowserCommand(args);
        },
    },
    {
        name: 'cleanup',
        aliases: ['--cleanup'],
        handle: async (args) => {
            const { handleCleanupCommand } = await Promise.resolve().then(() => __importStar(require('./cleanup-command')));
            await handleCleanupCommand(args);
        },
    },
    {
        name: 'auth',
        handle: async (args) => {
            const AuthCommandsModule = await Promise.resolve().then(() => __importStar(require('../auth/auth-commands')));
            const AuthCommands = AuthCommandsModule.default;
            const authCommands = new AuthCommands();
            await authCommands.route(args);
        },
    },
    {
        name: 'api',
        handle: async (args) => {
            const { handleApiCommand } = await Promise.resolve().then(() => __importStar(require('./api-command/index')));
            await handleApiCommand(args);
        },
    },
    {
        name: 'cliproxy',
        handle: async (args) => {
            const { handleCliproxyCommand } = await Promise.resolve().then(() => __importStar(require('./cliproxy-command')));
            await handleCliproxyCommand(args);
        },
    },
    {
        name: 'proxy',
        handle: async (args) => {
            const { handleProxyCommand } = await Promise.resolve().then(() => __importStar(require('./proxy-command')));
            process.exit(await handleProxyCommand(args));
        },
    },
    {
        name: 'docker',
        handle: async (args) => {
            const { handleDockerCommand } = await Promise.resolve().then(() => __importStar(require('./docker-command')));
            await handleDockerCommand(args);
        },
    },
    {
        name: 'config',
        handle: async (args) => {
            const { handleConfigCommand } = await Promise.resolve().then(() => __importStar(require('./config-command')));
            await handleConfigCommand(args);
        },
    },
    {
        name: 'tokens',
        handle: async (args) => {
            const { handleTokensCommand } = await Promise.resolve().then(() => __importStar(require('./tokens-command')));
            process.exit(await handleTokensCommand(args));
        },
    },
    {
        name: 'persist',
        handle: async (args) => {
            const { handlePersistCommand } = await Promise.resolve().then(() => __importStar(require('./persist-command')));
            await handlePersistCommand(args);
        },
    },
    {
        name: 'env',
        handle: async (args) => {
            const { handleEnvCommand } = await Promise.resolve().then(() => __importStar(require('./env-command')));
            await handleEnvCommand(args);
        },
    },
    {
        name: 'setup',
        aliases: ['--setup'],
        handle: async (args) => {
            const { handleSetupCommand } = await Promise.resolve().then(() => __importStar(require('./setup-command')));
            await handleSetupCommand(args);
        },
    },
];
async function tryHandleRootCommand(args) {
    const route = (0, named_command_router_1.resolveNamedCommand)(args[0], exports.ROOT_COMMAND_ROUTES);
    if (!route) {
        return false;
    }
    await route.handle(args.slice(1));
    return true;
}
exports.tryHandleRootCommand = tryHandleRootCommand;
//# sourceMappingURL=root-command-router.js.map