"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureCompileCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const FeatureGraphCompiler_1 = require("../services/FeatureGraphCompiler");
exports.FeatureCompileCommand = new commander_1.Command("feature:compile")
    .description("Re-compile the feature graph from context.json")
    .option("--json", "output compiled graph as JSON")
    .action(async (options) => {
    const compiler = new FeatureGraphCompiler_1.FeatureGraphCompiler();
    const graph = await compiler.compileFromContext();
    const features = Array.from(graph.nodes.values());
    console.log(chalk_1.default.bold("\n🔄 Feature Graph Compiled"));
    console.log(chalk_1.default.dim("─".repeat(50)));
    console.log(`  ${chalk_1.default.cyan("Features:")}    ${features.length}`);
    console.log(`  ${chalk_1.default.cyan("Dependencies:")} ${graph.edges.length}`);
    console.log(`  ${chalk_1.default.cyan("Roots:")}       ${graph.rootIds.length}`);
    const byStatus = {};
    const byPriority = {};
    for (const f of features) {
        byStatus[f.status] = (byStatus[f.status] || 0) + 1;
        byPriority[f.priority] = (byPriority[f.priority] || 0) + 1;
    }
    console.log(chalk_1.default.dim("\n  By Status:"));
    for (const [status, count] of Object.entries(byStatus)) {
        console.log(`    · ${status}: ${count}`);
    }
    console.log(chalk_1.default.dim("\n  By Priority:"));
    for (const [priority, count] of Object.entries(byPriority)) {
        console.log(`    · ${priority}: ${count}`);
    }
    const avgCompleteness = features.length > 0
        ? Math.round(features.reduce((s, f) => s + f.completeness.overall, 0) /
            features.length)
        : 0;
    console.log(`\n  ${chalk_1.default.cyan("Avg Completeness:")} ${avgCompleteness}%`);
    const recommended = graph.getNextRecommended();
    if (recommended) {
        console.log(`\n  ${chalk_1.default.green("→ Next recommended:")} ${recommended.name}`);
    }
    console.log(chalk_1.default.dim("─".repeat(50)));
    console.log();
    if (options.json) {
        console.log(JSON.stringify({
            features: features.map((f) => ({
                id: f.id,
                name: f.name,
                status: f.status,
                priority: f.priority,
                completeness: f.completeness,
            })),
            edges: graph.edges,
            rootIds: graph.rootIds,
        }, null, 2));
    }
});
//# sourceMappingURL=feature-compile.js.map