"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureValidateCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const FeatureGraphCompiler_1 = require("../services/FeatureGraphCompiler");
exports.FeatureValidateCommand = new commander_1.Command("feature:validate")
    .description("Validate feature completeness and detect gaps")
    .argument("[feature-id]", "feature ID to validate (validates all if omitted)")
    .option("--json", "output as JSON")
    .action(async (featureId, options) => {
    const compiler = new FeatureGraphCompiler_1.FeatureGraphCompiler();
    const graph = await compiler.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 to validate"));
        process.exit(1);
    }
    const results = [];
    for (const feature of features) {
        const gaps = await compiler.detectGaps(feature);
        results.push({
            id: feature.id,
            name: feature.name,
            completeness: feature.completeness,
            gaps,
            passed: gaps.length === 0,
        });
    }
    if (options.json) {
        console.log(JSON.stringify(results, null, 2));
        return;
    }
    let allPassed = true;
    for (const result of results) {
        const status = result.passed
            ? chalk_1.default.green("✓ PASS")
            : chalk_1.default.red("✗ FAIL");
        console.log(`\n  ${status} ${chalk_1.default.bold(result.name)} ${chalk_1.default.dim(`(${result.id})`)}`);
        console.log(`     Completeness: ${result.completeness.overall}%`);
        if (result.gaps.length > 0) {
            allPassed = false;
            for (const gap of result.gaps) {
                console.log(`     ${chalk_1.default.yellow("⚠")} ${gap.message}`);
            }
        }
    }
    console.log();
    if (allPassed) {
        console.log(chalk_1.default.green("  ✓ All features passed validation"));
    }
    else {
        console.log(chalk_1.default.yellow("  ⚠ Some features have gaps that need attention"));
    }
    console.log();
});
//# sourceMappingURL=feature-validate.js.map