"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findDuplicateSpecIds = findDuplicateSpecIds;
const cli_constants_1 = require("../config/cli-constants");
/**
 * Detect duplicate spec IDs across registry entries.
 * Returns grouped findings for each duplicate-ID cluster.
 */
function findDuplicateSpecIds(entries) {
    const idGroups = new Map();
    const findings = [];
    // Group entries by ID
    for (const entry of entries) {
        if (!idGroups.has(entry.id)) {
            idGroups.set(entry.id, []);
        }
        idGroups.get(entry.id).push(entry);
    }
    // Find duplicates and create findings
    for (const [id, group] of idGroups.entries()) {
        if (group.length > 1) {
            findings.push({
                code: "SPEC_REGISTRY_DUPLICATE_ID",
                message: `Spec ID '${id}' is duplicated: found in ${group.length} entries.`,
                severity: "error",
                path: cli_constants_1.CLI_SPEC_INDEX_PATH
            });
        }
    }
    return {
        hasDuplicates: findings.length > 0,
        findings: Object.freeze(findings),
        duplicateIdGroups: new Map(Array.from(idGroups.entries()).filter(([, group]) => group.length > 1))
    };
}
