"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CHANGED_PATH_NO_GIT_DISCOVERY_BOUNDARY = exports.CHANGED_PATH_INPUT_SOURCE = void 0;
exports.normalizeChangedPathInputs = normalizeChangedPathInputs;
const paths_1 = require("../paths");
exports.CHANGED_PATH_INPUT_SOURCE = "explicit-caller-provided-input";
exports.CHANGED_PATH_NO_GIT_DISCOVERY_BOUNDARY = "Changed paths must be supplied explicitly by the caller; this contract does not inspect Git status, staged files, commits, diffs, remotes, or any other Git-backed changed-file source.";
function normalizeChangedPathInputs(changedPaths) {
    const normalizedChangedPaths = [];
    const evidence = [];
    const seenPaths = new Set();
    for (const rawInput of changedPaths) {
        const destinationResult = (0, paths_1.validateWriteDestination)(rawInput);
        if (!destinationResult.ok) {
            evidence.push({
                state: "invalid-input",
                rawInput,
                inputSource: exports.CHANGED_PATH_INPUT_SOURCE,
                rejectionCode: destinationResult.rejection.code,
                blocking: true,
                recovery: "Supply a canonical repository-relative changed path before running diff-check automation.",
                message: `Changed path '${rawInput}' is invalid: ${destinationResult.rejection.reason}`
            });
            continue;
        }
        const normalizedPath = destinationResult.value.repositoryRelativePath.normalizedPath;
        if (seenPaths.has(normalizedPath)) {
            evidence.push({
                state: "duplicate",
                rawInput,
                inputSource: exports.CHANGED_PATH_INPUT_SOURCE,
                normalizedPath,
                duplicateOf: normalizedPath,
                blocking: false,
                recovery: "No recovery is required; duplicate changed-path evidence is retained for diagnostics and the canonical path is evaluated once.",
                message: `Changed path '${rawInput}' duplicates normalized path '${normalizedPath}'.`
            });
            continue;
        }
        seenPaths.add(normalizedPath);
        normalizedChangedPaths.push(normalizedPath);
        evidence.push({
            state: "normalized",
            rawInput,
            inputSource: exports.CHANGED_PATH_INPUT_SOURCE,
            normalizedPath,
            blocking: false,
            recovery: "No recovery is required.",
            message: `Changed path '${rawInput}' normalized to '${normalizedPath}'.`
        });
    }
    return {
        normalizedChangedPaths,
        evidence,
        inputSource: exports.CHANGED_PATH_INPUT_SOURCE,
        gitDiscoveryPerformed: false,
        noGitDiscoveryBoundary: exports.CHANGED_PATH_NO_GIT_DISCOVERY_BOUNDARY
    };
}
