import BaseApplicationGenerator from '../base-application/index.js';
import { GENERATOR_APP } from '../generator-list.js';
import command from './command.js';
export default class EntitiesGenerator extends BaseApplicationGenerator {
    entities;
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints();
        }
    }
    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);
                }
            },
            async parseCommand() {
                await this.parseCurrentJHipsterCommand();
            },
        });
    }
    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);
    }
}
