import { rulesNames } from './rules.js';
import FieldIssue from './issues/field-issue.js';
let issues;
export function checkFields(entityName, fieldDeclarations) {
    if (fieldDeclarations.length === 0) {
        return [];
    }
    issues = [];
    checkForDuplicatedFields(entityName, fieldDeclarations);
    return issues;
}
function checkForDuplicatedFields(entityName, fieldDeclarations) {
    const fieldNames = new Set();
    const duplicatedFieldIssues = new Map();
    fieldDeclarations.forEach(fieldDeclaration => {
        const fieldName = fieldDeclaration.children.NAME[0].image;
        if (fieldNames.has(fieldName)) {
            if (!duplicatedFieldIssues.has(fieldName)) {
                duplicatedFieldIssues.set(fieldName, new FieldIssue({
                    ruleName: rulesNames.FLD_DUPLICATED,
                    fieldName,
                    entityName,
                }));
            }
        }
        else {
            fieldNames.add(fieldName);
        }
    });
    duplicatedFieldIssues.forEach(issue => {
        issues.push(issue);
    });
}
