import { join } from '../utils/set-utils.js';
export default class JDLApplicationEntities {
    entityNames;
    constructor(entityNames = []) {
        this.entityNames = new Set(entityNames);
    }
    add(entityName) {
        if (!entityName) {
            throw new Error('An entity name has to be passed so as to be added.');
        }
        this.entityNames.add(entityName);
    }
    addEntityNames(entityNames = []) {
        const filteredNames = entityNames.filter(entityName => !!entityName);
        this.entityNames = new Set([...this.entityNames, ...filteredNames]);
    }
    has(entityName) {
        return this.entityNames.has(entityName);
    }
    forEach(passedFunction) {
        if (!passedFunction) {
            return;
        }
        this.entityNames.forEach(entityName => {
            passedFunction(entityName);
        });
    }
    toArray() {
        return Array.from(this.entityNames);
    }
    size() {
        return this.entityNames.size;
    }
    toString(indent = 0) {
        if (this.entityNames.size === 0) {
            return '';
        }
        const spaceBefore = ' '.repeat(indent);
        return `${spaceBefore}entities ${join(this.entityNames, ', ')}`;
    }
}
