import { Args, Flags } from '@oclif/core';
import { PMOCommand, pmoBaseFlags } from '../../lib/pmo/index.js';
import { styles } from '../../lib/styles.js';
import { shouldOutputJson, outputErrorAsJson, createMetadata, } from '../../lib/prompt-json.js';
import { FlagResolver } from '../../lib/flags/index.js';
export default class PhaseDelete extends PMOCommand {
    static description = 'Delete a project lifecycle phase';
    static examples = [
        '<%= config.bin %> <%= command.id %> on-hold',
        '<%= config.bin %> <%= command.id %> on-hold --force',
    ];
    static args = {
        id: Args.string({
            description: 'Phase ID',
            required: true,
        }),
    };
    static flags = {
        ...pmoBaseFlags,
        force: Flags.boolean({
            char: 'f',
            description: 'Skip confirmation',
            default: false,
        }),
    };
    getPMOOptions() {
        return { promptIfMultiple: false };
    }
    async execute() {
        const { args, flags } = await this.parse(PhaseDelete);
        // Check if JSON output mode is active
        const jsonMode = shouldOutputJson(flags);
        // Helper to handle errors in JSON mode
        const handleError = (code, message) => {
            if (jsonMode) {
                outputErrorAsJson(code, message, createMetadata('phase delete', flags));
                this.exit(1);
            }
            this.error(message);
        };
        const phase = await this.storage.getPhase(args.id);
        if (!phase) {
            return handleError('PHASE_NOT_FOUND', `Phase "${args.id}" not found.`);
        }
        if (!flags.force) {
            // Use FlagResolver for confirmation
            const resolver = new FlagResolver({
                commandName: 'phase delete',
                baseCommand: `prlt phase delete ${args.id}`,
                jsonMode,
                flags: { json: flags.json, machine: flags.machine },
            });
            resolver.addPrompt({
                flagName: 'confirmed',
                type: 'list',
                message: `Delete phase "${phase.name}"?`,
                choices: () => [
                    { name: 'No', value: false },
                    { name: 'Yes', value: true },
                ],
                getCommand: (value) => value
                    ? `prlt phase delete ${args.id} --force --json`
                    : '',
            });
            const resolved = await resolver.resolve();
            if (!resolved.confirmed) {
                this.log(styles.muted('Cancelled.'));
                return;
            }
        }
        await this.storage.deletePhase(args.id);
        this.log(styles.success(`\nDeleted phase "${phase.name}"`));
    }
}
//# sourceMappingURL=delete.js.map