import { merge } from '../utils/object-utils.js';
import { upperFirst } from '../utils/string-utils.js';
class JSONEntity {
    constructor(args) {
        if (!args || !args.entityName) {
            throw new Error('At least an entity name must be passed.');
        }
        const merged = merge(getDefaults(args.entityName), args);
        this.name = merged.name;
        this.fields = merged.fields;
        this.relationships = merged.relationships;
        this.documentation = merged.documentation;
        this.entityTableName = merged.entityTableName;
        this.dto = merged.dto;
        this.pagination = merged.pagination;
        this.service = merged.service;
        this.jpaMetamodelFiltering = merged.jpaMetamodelFiltering;
        this.fluentMethods = merged.fluentMethods;
        this.readOnly = merged.readOnly;
        this.embedded = merged.embedded;
        if (merged.clientRootFolder) {
            this.clientRootFolder = merged.clientRootFolder;
        }
        if (merged.microserviceName) {
            this.microserviceName = merged.microserviceName;
        }
        if (merged.angularJSSuffix) {
            this.angularJSSuffix = merged.angularJSSuffix;
        }
        if (merged.skipServer) {
            this.skipServer = merged.skipServer;
        }
        if (merged.skipClient) {
            this.skipClient = merged.skipClient;
        }
        this.applications = [];
    }
    addFields(fields) {
        if (!fields || fields.length === 0) {
            return;
        }
        this.fields = this.fields.concat(fields);
    }
    addField(field) {
        if (field) {
            this.fields.push(field);
        }
    }
    addRelationships(relationships) {
        if (!relationships || relationships.length === 0) {
            return;
        }
        this.relationships = this.relationships.concat(relationships);
    }
    addRelationship(relationship) {
        if (relationship) {
            this.relationships.push(relationship);
        }
    }
    setOptions(options = {}) {
        Object.keys(options).forEach(optionName => {
            this[optionName] = options[optionName];
        });
    }
}
export default JSONEntity;
function getDefaults(entityName) {
    return {
        name: upperFirst(entityName),
        fields: [],
        relationships: [],
        applications: [],
    };
}
