"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createValidationCheckpointCommand = createValidationCheckpointCommand;
const output_1 = require("../../../lib/output");
const runtime_contract_1 = require("../../../lib/runtime/runtime-contract");
const errors_1 = require("../../../lib/errors");
const doctor_1 = require("../../../lib/doctor");
const global_format_1 = require("../global-format");
async function createValidationCheckpointCommand() {
    const { Command } = await import("commander");
    const command = new Command("checkpoint");
    command
        .description("Write a forward-only planning validation baseline from current repo-wide smoke findings.")
        .option("--scope <scope>", "Validation checkpoint scope. Currently only 'planning' is supported.", "planning")
        .action((_, commandInstance) => {
        const format = (0, output_1.resolveOutputFormat)((0, global_format_1.getGlobalFormat)(commandInstance));
        if (format === null) {
            throw (0, errors_1.createUsageError)("Output format must be one of: text, json.", [`Received: ${String((0, global_format_1.getGlobalFormat)(commandInstance))}`]);
        }
        const options = commandInstance.opts();
        if (options.scope !== "planning") {
            throw (0, errors_1.createUsageError)("Validation checkpoint currently supports only the 'planning' scope.", [`Received: ${String(options.scope)}`]);
        }
        const repositoryContext = (0, runtime_contract_1.createRepositoryContext)((0, runtime_contract_1.detectRepositoryRoot)(), false);
        const baseline = (0, doctor_1.writePlanningValidationBaseline)({
            repositoryRoot: repositoryContext.root
        });
        const totalBaselineEntries = baseline.findings.length
            + baseline.inventory_findings.length
            + baseline.gaps.length;
        (0, output_1.emitSuccess)({
            command: "validation checkpoint",
            format,
            text: [
                "Day Shift validation checkpoint",
                `Repository root: ${repositoryContext.root}`,
                `Detection source: ${repositoryContext.detectionSource}`,
                `Scope: ${baseline.scope}`,
                `Mode: ${baseline.mode}`,
                `Checkpoint path: ${baseline.path}`,
                `Created at: ${baseline.created_at}`,
                `Baseline entries: ${totalBaselineEntries} total, ${baseline.findings.length} findings, ${baseline.inventory_findings.length} inventory findings, ${baseline.gaps.length} gaps`
            ].join("\n"),
            data: {
                repositoryRoot: repositoryContext.root,
                detectionSource: repositoryContext.detectionSource,
                path: baseline.path,
                schemaVersion: baseline.schema_version,
                createdAt: baseline.created_at,
                scope: baseline.scope,
                mode: baseline.mode,
                findingCount: baseline.findings.length,
                inventoryFindingCount: baseline.inventory_findings.length,
                gapCount: baseline.gaps.length,
                totalBaselineEntries
            }
        });
    });
    return command;
}
