"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaultReconciliationSections = getDefaultReconciliationSections;
exports.getDefaultTaskReconciliationSections = getDefaultTaskReconciliationSections;
exports.buildTaskAcceptanceFallbackText = buildTaskAcceptanceFallbackText;
exports.buildTaskValidationFallbackText = buildTaskValidationFallbackText;
// Responsibility-focused implementation extracted from the public compatibility facade.
const contracts_1 = require("../implementation-summary/contracts");
const semantic_placeholder_1 = require("../semantic-placeholder");
const milestone_evidence_1 = require("./milestone-evidence");
const selector_evidence_1 = require("./selector-evidence");
function getDefaultReconciliationSections(taskEvidence, context) {
    return {
        "Review Status": (0, milestone_evidence_1.buildReviewStatusText)(taskEvidence),
        "Milestone Intent": (0, milestone_evidence_1.buildMilestoneIntentText)(context),
        "Completed Task Summaries": (0, milestone_evidence_1.buildCompletedTaskSummariesText)(taskEvidence.completed),
        "Acceptance Criteria Review": (0, milestone_evidence_1.buildAcceptanceCriteriaReviewText)(taskEvidence, context),
        "Planned Work": (0, milestone_evidence_1.buildPlannedWorkText)(taskEvidence),
        "Resolved Findings": "None.",
        "Discovered Work": "None.",
        "Backlog Work": "None.",
        "Accepted Residual Work": "None.",
        "Validation Review": (0, milestone_evidence_1.buildValidationReviewText)(taskEvidence.completed, context),
        "Follow-Up Tasks": "None.",
        "Review Concerns": (0, milestone_evidence_1.buildReviewConcernsText)(taskEvidence),
        "Final Notes": taskEvidence.completed.length === 0
            ? "Milestone evidence has been refreshed; no completed task implementation summaries are available yet."
            : contracts_1.MILESTONE_FINAL_REVIEW_MARKER
    };
}
function getDefaultTaskReconciliationSections(context, taskEvidence, rationale) {
    const hasCompletedSummary = (0, milestone_evidence_1.isReconciliationCompletedSummaryEvidence)(taskEvidence);
    return {
        "Review Status": [
            "Task-level reconciliation exception selected explicitly from the source task definition.",
            `Source task definition: ${context.taskDefinitionPath}.`,
            `Parent milestone overview: ${context.milestoneOverviewPath ?? "(missing)"}.`,
            `Exception rationale: ${rationale}.`,
            contracts_1.TASK_RECONCILIATION_REVIEW_MARKER
        ].join("\n"),
        "Original Intent": context.objectiveText === null || (0, semantic_placeholder_1.hasSemanticPlaceholderContent)(context.objectiveText)
            ? "Review this task against its task-definition objective and acceptance criteria."
            : context.objectiveText,
        "Completed Work": taskEvidence.summaryText ?? "No paired implementation summary evidence is available yet.",
        "Acceptance Criteria Review": taskEvidence.acceptanceCriteriaText ?? buildTaskAcceptanceFallbackText(context),
        "Planned Work": hasCompletedSummary
            ? "No remaining planned work was inferred by task-level reconciliation build."
            : `Paired implementation summary remains incomplete (implementation_status: ${taskEvidence.implementationStatus || "(missing)"}).`,
        "Resolved Findings": "None identified by build refresh.",
        "Discovered Work": "None identified by build refresh.",
        "Backlog Work": "None identified by build refresh.",
        "Accepted Residual Work": "None identified by build refresh.",
        "Validation Review": taskEvidence.validationText ?? buildTaskValidationFallbackText(context),
        "Follow-Up Tasks": "None identified by build refresh.",
        "Review Concerns": hasCompletedSummary
            ? "Task-level reconciliation remains an explicit exception; milestone-level reconciliation is still the default rollup."
            : "Task-level reconciliation was created before paired implementation-summary closeout evidence was complete.",
        "Final Notes": contracts_1.TASK_RECONCILIATION_FINAL_REVIEW_MARKER
    };
}
function buildTaskAcceptanceFallbackText(context) {
    if (context.acceptanceCriteriaText === null || (0, semantic_placeholder_1.hasSemanticPlaceholderContent)(context.acceptanceCriteriaText)) {
        return "No paired implementation-summary acceptance evidence is available yet.";
    }
    return [
        "Task acceptance criteria from the task definition:",
        ...(0, selector_evidence_1.normalizeReviewLines)(context.acceptanceCriteriaText),
        "",
        "No paired implementation-summary acceptance evidence is available yet."
    ].join("\n");
}
function buildTaskValidationFallbackText(context) {
    if (context.validationCommandsText === null || (0, semantic_placeholder_1.hasSemanticPlaceholderContent)(context.validationCommandsText)) {
        return "No paired implementation-summary validation evidence is available yet.";
    }
    return [
        "Task validation commands from the task definition:",
        ...(0, selector_evidence_1.normalizeReviewLines)(context.validationCommandsText),
        "",
        "No paired implementation-summary validation evidence is available yet."
    ].join("\n");
}
