import AigcIssue from './issues/aigc-issue.js';
import { rulesNames } from './rules.js';
import { aigcTypes } from '../jhipster/index.js';
import { aiTypes } from "../basic-types/aigc-type.js";
let issues;
export default {
    checkAigcs,
};
export function checkAigcs(aigcDeclarations) {
    if (!aigcDeclarations || aigcDeclarations.length === 0) {
        return [];
    }
    issues = [];
    checkForCollapsibleRelationships(aigcDeclarations);
    return issues;
}
function checkForCollapsibleRelationships(aigcDeclarations) {
    const sortedAigcs = {
        [aigcTypes.METHOD]: [],
        [aiTypes.API]: [],
        [aiTypes.FEATURE]: [],
    };
    aigcDeclarations.forEach((aigcDeclaration) => {
        const type = aigcDeclaration.children.aigcType[0].children.AIGC_TYPE[0].image;
        const from = aigcDeclaration.children.aigcBody[0].children.from[0].children.NAME[0].image;
        const to = aigcDeclaration.children.aigcBody[0].children.to[0].NAME[0].image;
        sortedAigcs[type].push({ from, to });
    });
    Object.keys(sortedAigcs).forEach(type => {
        if (sortedAigcs[type].length > 1) {
            sortedAigcs[type].forEach(aigc => {
                issues.push(new AigcIssue({
                    ruleName: rulesNames.REL_INDIVIDUAL_DECL,
                    from: aigc.from,
                    to: aigc.to,
                    type,
                }));
            });
        }
    });
}
