import { lowerFirst } from 'lodash-es';
import { JDLEntity } from '../../models/index.mjs';
import { formatComment } from '../../utils/format-utils.js';
export default { convertEntities };
export function convertEntities(parsedEntities, jdlFieldGetterFunction) {
    if (!parsedEntities) {
        throw new Error('Entities have to be passed so as to be converted.');
    }
    return parsedEntities.map(parsedEntity => {
        const jdlEntity = new JDLEntity({
            name: parsedEntity.name,
            tableName: parsedEntity.tableName || parsedEntity.name,
            comment: formatComment(parsedEntity.documentation),
            annotations: Object.fromEntries(parsedEntity.annotations?.map(annotation => [
                lowerFirst(annotation.optionName),
                annotation.type === 'UNARY' ? true : annotation.optionValue,
            ]) ?? []),
        });
        const jdlFields = jdlFieldGetterFunction.call(undefined, parsedEntity);
        jdlEntity.addFields(jdlFields);
        return jdlEntity;
    });
}
