"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeRequestedImplementationPaths = normalizeRequestedImplementationPaths;
const paths_1 = require("../paths");
function normalizeRequestedImplementationPaths(requestedPaths) {
    const normalizedRequestedPaths = [];
    const evidence = [];
    const seenPaths = new Set();
    for (const rawInput of requestedPaths) {
        const destinationResult = (0, paths_1.validateWriteDestination)(rawInput);
        if (!destinationResult.ok) {
            evidence.push({
                state: "invalid-input",
                rawInput,
                rejectionCode: destinationResult.rejection.code,
                message: `Requested implementation path '${rawInput}' is invalid: ${destinationResult.rejection.reason}`
            });
            continue;
        }
        const normalizedPath = destinationResult.value.repositoryRelativePath.normalizedPath;
        if (seenPaths.has(normalizedPath)) {
            evidence.push({
                state: "duplicate",
                rawInput,
                normalizedPath,
                duplicateOf: normalizedPath,
                message: `Requested implementation path '${rawInput}' duplicates normalized path '${normalizedPath}'.`
            });
            continue;
        }
        seenPaths.add(normalizedPath);
        normalizedRequestedPaths.push(normalizedPath);
        evidence.push({
            state: "normalized",
            rawInput,
            normalizedPath,
            message: `Requested implementation path '${rawInput}' normalized to '${normalizedPath}'.`
        });
    }
    return {
        normalizedRequestedPaths,
        evidence
    };
}
