"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DoctorCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const DoctorEngine_1 = require("../doctor/DoctorEngine");
class DoctorCommand {
    register(program) {
        program
            .command("doctor [directory]")
            .description("🩺 Diagnose and fix project issues")
            .option("--fix", "Auto-fix all fixable issues")
            .option("--verbose", "Show file details per rule")
            .option("--score", "Output only the score")
            .option("--project <name>", "Select workspace project (monorepo)")
            .option("--scope <path>", "Limit diagnostics to specific directory or package")
            .option("--category <cat>", "Run only a specific category (nextjs|turbo|node|dead)")
            .option("--dry-run", "Show what --fix would do without changing files")
            .option("--prune", "Prune dead code (destructive)")
            .option("--json", "Output JSON (for programmatic use)")
            .option("--red-team", "Launch agentic red-team probes (deep security analysis)")
            .action(async (directory, opts) => {
            await this.run(directory || ".", {
                fix: opts.fix,
                verbose: opts.verbose,
                score: opts.score,
                project: opts.project,
                scope: opts.scope,
                category: opts.category,
                dryRun: opts.dryRun,
                json: opts.json,
                prune: opts.prune,
                redTeam: opts.redTeam,
            });
        });
    }
    async run(directory, options) {
        try {
            const result = await (0, DoctorEngine_1.runDoctor)(directory, options);
            // Display results
            (0, DoctorEngine_1.displayResult)(result, options);
            // Exit with error code if there are errors (for CI)
            if (options.score && result.score < 50) {
                process.exit(1);
            }
        }
        catch (error) {
            console.error(chalk_1.default.red(`\n❌ Doctor failed: ${error.message}\n`));
            if (options.verbose) {
                console.error(error.stack);
            }
            process.exit(1);
        }
    }
}
exports.DoctorCommand = DoctorCommand;
//# sourceMappingURL=doctor.js.map