import BaseApplicationGenerator from '../base-application/index.mjs';
import { GENERATOR_SPRING_DATA_MONGODB, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs';
import writeMongodbFilesTask from './files.mjs';
import cleanupMongodbFilesTask from './cleanup.mjs';
import writeMongodbEntityFilesTask, { cleanupMongodbEntityFilesTask } from './entity-files.mjs';
export default class MongoDBGenerator extends BaseApplicationGenerator {
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints(GENERATOR_SPRING_DATA_MONGODB);
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
        }
    }
    get writing() {
        return {
            cleanupMongodbFilesTask,
            writeMongodbFilesTask,
        };
    }
    get [BaseApplicationGenerator.WRITING]() {
        return this.delegateTasksToBlueprint(() => this.writing);
    }
    get writingEntities() {
        return {
            cleanupMongodbEntityFilesTask,
            writeMongodbEntityFilesTask,
        };
    }
    get [BaseApplicationGenerator.WRITING_ENTITIES]() {
        return this.delegateTasksToBlueprint(() => this.writingEntities);
    }
    get postWriting() {
        return this.asPostWritingTaskGroup({
            addDependencies({ application, source }) {
                const { reactive } = application;
                if (application.buildToolMaven) {
                    source.addMavenDefinition?.({
                        dependencies: [
                            { groupId: 'io.mongock', artifactId: 'mongock-springboot-v3' },
                            { groupId: 'org.springframework.boot', artifactId: `spring-boot-starter-data-mongodb${reactive ? '-reactive' : ''}` },
                            { groupId: 'org.testcontainers', artifactId: 'junit-jupiter', scope: 'test' },
                            { groupId: 'org.testcontainers', artifactId: 'testcontainers', scope: 'test' },
                            { groupId: 'org.testcontainers', artifactId: 'mongodb', scope: 'test' },
                        ],
                        dependencyManagement: [
                            { groupId: 'org.reflections', artifactId: 'reflections', version: '0.10.1' },
                        ],
                    });
                    if (reactive) {
                        source.addMavenDefinition?.({
                            dependencies: [
                                { groupId: 'org.springframework.boot', artifactId: 'spring-boot-starter-data-mongodb' },
                                { groupId: 'io.mongock', artifactId: 'mongodb-springdata-v4-driver' },
                            ],
                        });
                    }
                    else {
                        source.addMavenDefinition?.({
                            dependencies: [{ groupId: 'io.mongock', artifactId: 'mongodb-springdata-v4-driver' }],
                        });
                    }
                }
            },
        });
    }
    get [BaseApplicationGenerator.POST_WRITING]() {
        return this.asPostWritingTaskGroup(this.delegateTasksToBlueprint(() => this.postWriting));
    }
}
