import BaseApplicationGenerator from '../base-application/index.mjs';
import { GENERATOR_ENTITIES, GENERATOR_APP } from '../generator-list.mjs';
import command from './command.mjs';
export default class EntitiesGenerator extends BaseApplicationGenerator {
    entities;
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints(GENERATOR_ENTITIES);
        }
    }
    get initializing() {
        return this.asInitializingTaskGroup({
            loadArguments() {
                this.jhipsterConfig.entities = this.jhipsterConfig.entities || [];
                this.parseJHipsterArguments(command.arguments);
                if (!this.entities || this.entities.length === 0) {
                    this.entities = this.getExistingEntityNames();
                }
                else {
                    for (const entity of this.entities) {
                        if (!this.jhipsterConfig.entities.includes(entity)) {
                            this.jhipsterConfig.entities.push(entity);
                        }
                    }
                }
                if (this.entities) {
                    this.log.verboseInfo('Generating entities', ...this.entities);
                }
            },
            loadOptions() {
                this.parseJHipsterOptions(command.options);
            },
        });
    }
    get [BaseApplicationGenerator.INITIALIZING]() {
        return this.delegateTasksToBlueprint(() => this.initializing);
    }
    get composing() {
        return {
            async composeApp() {
                await this.composeWithJHipster(GENERATOR_APP, {
                    generatorOptions: { skipPriorities: ['writing', 'postWriting'], entities: this.entities },
                });
            },
        };
    }
    get [BaseApplicationGenerator.COMPOSING]() {
        return this.delegateTasksToBlueprint(() => this.composing);
    }
}
