"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImplGraphCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const FeatureGraphCompiler_1 = require("../services/FeatureGraphCompiler");
const ImplGraphCompiler_1 = require("../services/ImplGraphCompiler");
exports.ImplGraphCommand = new commander_1.Command("implementation:graph")
    .description("Show the full implementation graph")
    .argument("[feature-id]", "feature ID to show (shows all if omitted)")
    .option("--json", "output as JSON")
    .action(async (featureId, options) => {
    const featureCompiler = new FeatureGraphCompiler_1.FeatureGraphCompiler();
    const graph = await featureCompiler.compileFromContext();
    const features = featureId
        ? [graph.getFeatureById(featureId)].filter(Boolean)
        : Array.from(graph.nodes.values());
    if (features.length === 0) {
        console.error(chalk_1.default.red("No features found"));
        process.exit(1);
    }
    if (options.json) {
        const allResults = [];
        for (const feature of features) {
            const implCompiler = new ImplGraphCompiler_1.ImplGraphCompiler();
            const implGraph = await implCompiler.compileFromFeature(feature);
            allResults.push({
                featureId: feature.id,
                featureName: feature.name,
                batches: implGraph.batches.map(b => ({
                    id: b.id,
                    type: b.type,
                    label: b.label,
                    status: b.status,
                    taskCount: b.tasks.length,
                })),
                taskCount: implGraph.nodes.size,
            });
        }
        console.log(JSON.stringify(allResults, null, 2));
        return;
    }
    for (const feature of features) {
        const implCompiler = new ImplGraphCompiler_1.ImplGraphCompiler();
        const implGraph = await implCompiler.compileFromFeature(feature);
        console.log(chalk_1.default.bold(`\n🔧 ${feature.name} ${chalk_1.default.dim(`(${feature.id})`)}`));
        console.log(chalk_1.default.dim("─".repeat(50)));
        for (const batch of implGraph.batches) {
            console.log(`  ${chalk_1.default.cyan("▸")} ${chalk_1.default.bold(batch.label)} — ${batch.tasks.length} tasks`);
        }
        const total = implGraph.nodes.size;
        const pending = implGraph.getTasksByStatus("pending").length;
        console.log(chalk_1.default.dim(`  ${total} total tasks · ${pending} pending`));
    }
    console.log();
});
//# sourceMappingURL=impl-graph.js.map