"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMilestoneUpdateCommand = createMilestoneUpdateCommand;
const runtime_contract_1 = require("../../../lib/runtime/runtime-contract");
const metadata_update_operation_1 = require("../metadata-update-operation");
async function createMilestoneUpdateCommand() {
    const { Command } = await import("commander");
    const command = new Command("update");
    command
        .description("Apply helper-backed metadata field updates to an existing milestone overview artifact.")
        .requiredOption("--milestone-overview <path>", "Repository-relative milestone overview path to update.")
        .option("--active-artifact <path>", "Repository-relative active artifact path expected by the current handoff.")
        .option("--run-directory <path>", "Lifecycle run directory whose active artifact, gate, freshness, and metadata posture constrain this write.")
        .option("--field <key=value>", "Direct intended metadata update. Repeat for multiple fields.", collectFieldAssignment, [])
        .action((_, commandInstance) => {
        const repositoryContext = (0, runtime_contract_1.createRepositoryContext)((0, runtime_contract_1.detectRepositoryRoot)(), false);
        (0, metadata_update_operation_1.executeOverviewUpdateOperation)({
            commandName: "milestone update",
            write: true,
            commandInstance,
            artifactPathOption: "milestoneOverview",
            expectedArtifactType: "milestone_overview",
            repositoryRoot: repositoryContext.root,
            detectionSource: repositoryContext.detectionSource
        });
    });
    return command;
}
function collectFieldAssignment(value, previous) {
    previous.push(value);
    return previous;
}
