"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ImplBatchesCommand = 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.ImplBatchesCommand = new commander_1.Command("implementation:batches")
    .description("Show execution batches for all features")
    .argument("[feature-id]", "feature ID to show batches for")
    .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 allBatches = [];
        for (const feature of features) {
            const implCompiler = new ImplGraphCompiler_1.ImplGraphCompiler();
            const implGraph = await implCompiler.compileFromFeature(feature);
            for (const batch of implGraph.batches) {
                allBatches.push({
                    featureId: feature.id,
                    featureName: feature.name,
                    batchId: batch.id,
                    type: batch.type,
                    label: batch.label,
                    status: batch.status,
                    taskCount: batch.tasks.length,
                });
            }
        }
        console.log(JSON.stringify(allBatches, null, 2));
        return;
    }
    let totalTasks = 0;
    let totalBatches = 0;
    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) {
            const statusIcon = batch.status === "completed"
                ? chalk_1.default.green("✓")
                : batch.status === "in-progress"
                    ? chalk_1.default.yellow("●")
                    : chalk_1.default.dim("○");
            const typeColors = {
                model: chalk_1.default.blue,
                route: chalk_1.default.green,
                component: chalk_1.default.magenta,
                action: chalk_1.default.cyan,
                permission: chalk_1.default.yellow,
                i18n: chalk_1.default.white,
                test: chalk_1.default.red,
            };
            const typeColor = typeColors[batch.type] || chalk_1.default.dim;
            console.log(`  ${statusIcon} ${chalk_1.default.bold(batch.label)} ${typeColor(batch.type)} ${chalk_1.default.dim(`(${batch.tasks.length} tasks)`)}`);
            totalTasks += batch.tasks.length;
            totalBatches++;
        }
    }
    console.log(chalk_1.default.dim("\n─".repeat(50)));
    console.log(chalk_1.default.cyan(`  ${totalBatches} batches · ${totalTasks} tasks`));
    console.log();
});
//# sourceMappingURL=impl-batches.js.map