import inquirer from 'inquirer';
import { PMOCommand, pmoBaseFlags } from '../../lib/pmo/index.js';
import { shouldOutputJson } from '../../lib/prompt-json.js';
export default class Execution extends PMOCommand {
    static description = 'Single execution operations (view, logs, stop)';
    static examples = [
        '<%= config.bin %> <%= command.id %>',
        '<%= config.bin %> <%= command.id %> view WORK-001',
        '<%= config.bin %> <%= command.id %> logs WORK-001',
        '<%= config.bin %> <%= command.id %> stop WORK-001',
    ];
    static flags = {
        ...pmoBaseFlags,
    };
    getPMOOptions() {
        return { promptIfMultiple: false };
    }
    async execute() {
        const { flags } = await this.parse(Execution);
        const jsonModeConfig = shouldOutputJson(flags) ? { flags, commandName: 'execution' } : null;
        const { action } = await this.prompt([
            {
                type: 'list',
                name: 'action',
                message: 'What would you like to do?',
                choices: [
                    { name: '📋 List all executions', value: 'list', command: 'prlt execution list --json' },
                    { name: '🔍 View execution details', value: 'view', command: 'prlt execution view --json' },
                    { name: '📜 View logs for an execution', value: 'logs', command: 'prlt execution logs --json' },
                    { name: '🛑 Stop an execution', value: 'stop', command: 'prlt execution stop --json' },
                    { name: '🛑 Stop all running', value: 'stop-all', command: 'prlt execution stop --all --json' },
                    { name: '⚙️  Configure execution preferences', value: 'config', command: 'prlt execution config --json' },
                    new inquirer.Separator(),
                    { name: '❌ Cancel', value: 'cancel', command: '' },
                ],
            },
        ], jsonModeConfig);
        if (action === 'cancel') {
            return;
        }
        // Run the selected subcommand
        const commands = {
            list: { cmd: 'execution:list', args: [] },
            view: { cmd: 'execution:view', args: [] },
            logs: { cmd: 'execution:logs', args: [] },
            stop: { cmd: 'execution:stop', args: [] },
            'stop-all': { cmd: 'execution:stop', args: ['--all'] },
            config: { cmd: 'execution:config', args: [] },
        };
        const command = commands[action];
        if (command) {
            await this.config.runCommand(command.cmd, command.args);
        }
    }
}
//# sourceMappingURL=index.js.map