"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStructuralPressureSyncCommand = createStructuralPressureSyncCommand;
const errors_1 = require("../../../lib/errors");
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 createStructuralPressureSyncCommand() {
    const { Command } = await import("commander");
    const command = new Command("sync");
    command
        .description("Mirror one completed milestone reconciliation verdict into the derived structural-pressure JSON state.")
        .requiredOption("--milestone-reconciliation <path>", "Repository-relative path to the completed milestone reconciliation artifact.")
        .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 repositoryContext = (0, runtime_contract_1.createRepositoryContext)((0, runtime_contract_1.detectRepositoryRoot)(), false);
        const options = commandInstance.opts();
        const result = (0, structural_pressure_1.syncStructuralPressureState)(repositoryContext.root, {
            milestoneReconciliationPath: options.milestoneReconciliation
        });
        (0, output_1.emitSuccess)({
            command: "structural-pressure sync",
            format,
            text: (0, structural_pressure_1.renderStructuralPressureSyncResult)(result),
            data: {
                repositoryRoot: repositoryContext.root,
                detectionSource: repositoryContext.detectionSource,
                reconciliationPath: result.reconciliationPath,
                milestoneOverviewPath: result.milestoneOverviewPath,
                statePath: result.statePath,
                entryCount: result.entryCount,
                changed: result.changed,
                writeApplied: result.writeApplied
            }
        });
    });
    return command;
}
