import { addOtherRelationship } from '../../base-application/support/index.mjs';
export const addEntitiesOtherRelationships = (entities) => {
    const result = { warning: [] };
    for (const entity of entities) {
        for (const relationship of entity.relationships ?? []) {
            if (!relationship.otherRelationship &&
                (relationship.otherEntityRelationshipName ||
                    relationship.relationshipType === 'many-to-many' ||
                    (relationship.relationshipType === 'one-to-one' && entity.databaseType === 'sql') ||
                    (relationship.relationshipType === 'one-to-many' && entity.databaseType !== 'neo4j' && entity.databaseType !== 'no'))) {
                if (relationship.otherEntity.builtIn) {
                    result.warning.push(`Ignoring '${entity.name}' definitions as it is using a built-in Entity '${relationship.otherEntityName}': 'otherEntityRelationshipName' is set with value '${relationship.otherEntityRelationshipName}' at relationship '${relationship.relationshipName}' but no back-reference was found`);
                }
                else {
                    relationship.otherRelationship = addOtherRelationship(entity, relationship.otherEntity, relationship);
                }
            }
        }
    }
    return result;
};
