"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStructuralPressureReportCommand = createStructuralPressureReportCommand;
const errors_1 = require("../../../lib/errors");
const config_store_1 = require("../../../lib/config/config-store");
const output_1 = require("../../../lib/output");
const structural_pressure_1 = require("../../../lib/planning/structural-pressure");
const runtime_contract_1 = require("../../../lib/runtime/runtime-contract");
const global_format_1 = require("../global-format");
async function createStructuralPressureReportCommand() {
    const { Command } = await import("commander");
    const command = new Command("report");
    command
        .description("Report the current derived structural-pressure state plus linked planning evidence.")
        .option("--path <path>", "Repository-relative file/directory to scan. Defaults to src and tests.")
        .action((options, 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 repositoryContext = (0, runtime_contract_1.createRepositoryContext)((0, runtime_contract_1.detectRepositoryRoot)(), false);
        const configResult = (0, config_store_1.readResolvedConfig)(repositoryContext);
        const thresholds = (0, config_store_1.resolveStructuralPressureThresholds)(configResult.resolved);
        const exclusions = (0, structural_pressure_1.resolveStructuralPressureScanExclusions)(configResult.repositoryConfig.structural_pressure);
        const result = (0, structural_pressure_1.readStructuralPressureReport)(repositoryContext.root, {
            scanPath: options.path,
            thresholds,
            exclusions
        });
        (0, output_1.emitSuccess)({
            command: "structural-pressure report",
            format,
            text: (0, structural_pressure_1.renderStructuralPressureReport)(result),
            data: {
                repositoryRoot: repositoryContext.root,
                detectionSource: repositoryContext.detectionSource,
                statePath: result.statePath,
                statePresent: result.statePresent,
                sourceMilestoneReconciliationPath: result.sourceMilestoneReconciliationPath,
                sourceMilestoneOverviewPath: result.sourceMilestoneOverviewPath,
                syncedAt: result.syncedAt,
                thresholds: result.thresholds,
                entries: result.entries,
                driftFindings: result.driftFindings,
                scan: result.scan
            }
        });
    });
    return command;
}
