"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createReconciliationReviewCommand = createReconciliationReviewCommand;
const errors_1 = require("../../../lib/errors");
const implementation_summary_reconciliation_1 = require("../../../lib/planning/implementation-summary-reconciliation");
const output_1 = require("../../../lib/output");
const review_output_contracts_1 = require("../../../lib/planning/review-output-contracts");
const runtime_contract_1 = require("../../../lib/runtime/runtime-contract");
const global_format_1 = require("../global-format");
async function createReconciliationReviewCommand() {
    const { Command } = await import("commander");
    const command = new Command("review");
    command
        .description("Evaluate reconciliation evidence as a read-only, no-write surface; milestone rollup is the default, task-local review is an explicit exception.")
        .option("--milestone-overview <path>", "Repository-relative path to the milestone overview whose paired reconciliation should be reviewed.")
        .option("--task-definition <path>", "Repository-relative task-definition.md path for an explicit task-level reconciliation exception.")
        .option("--rationale <text>", "Required rationale when using --task-definition for an explicit task-level reconciliation exception.")
        .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, implementation_summary_reconciliation_1.reviewReconciliation)(repositoryContext.root, {
            milestoneOverviewPath: options.milestoneOverview,
            taskDefinitionPath: options.taskDefinition,
            taskReconciliationRationale: options.rationale
        });
        (0, output_1.emitSuccess)({
            command: "reconciliation review",
            format,
            text: (0, implementation_summary_reconciliation_1.renderReconciliationReviewResult)(result),
            data: {
                repositoryRoot: repositoryContext.root,
                detectionSource: repositoryContext.detectionSource,
                readOnly: true,
                writeCapable: false,
                noWriteBoundary: (0, review_output_contracts_1.getReviewOutputContract)("reconciliation review").noWriteBoundary,
                reviewOutputContract: (0, review_output_contracts_1.getReviewOutputContract)("reconciliation review"),
                mode: result.mode,
                milestoneOverviewPath: result.milestoneOverviewPath,
                taskDefinitionPath: result.taskDefinitionPath,
                reconciliationPath: result.reconciliationPath,
                reconciliationStatus: result.reconciliationStatus,
                artifactStatus: result.artifactStatus,
                closureEvidenceStatus: result.closureEvidenceStatus,
                evidenceGaps: result.evidenceGaps,
                placeholderResidue: result.placeholderResidue,
                alignmentIssues: result.alignmentIssues,
                reviewConcerns: result.reviewConcerns,
                blockingIssues: result.blockingIssues,
                warnings: result.warnings,
                metadataHygieneFollowUps: result.metadataHygieneFollowUps,
                recoveryGuidance: result.recoveryGuidance
            },
            findings: [...result.findings]
        });
    });
    return command;
}
