import BaseApplicationGenerator from '../../../base-application/index.js';
import { pulsarFiles } from './files.js';
export default class PulsarGenerator extends BaseApplicationGenerator {
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints();
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnBootstrapApplicationServer();
        }
    }
    get writing() {
        return this.asWritingTaskGroup({
            async writing({ application }) {
                await this.writeFiles({
                    sections: pulsarFiles,
                    context: application,
                });
            },
        });
    }
    get [BaseApplicationGenerator.WRITING]() {
        return this.delegateTasksToBlueprint(() => this.writing);
    }
    get postWriting() {
        return this.asPostWritingTaskGroup({
            customizeApplicationForPulsar({ source, application }) {
                source.addLogbackMainLog?.({ name: 'org.apache.pulsar', level: 'INFO' });
                source.addIntegrationTestAnnotation?.({ package: `${application.packageName}.config`, annotation: 'EmbeddedPulsar' });
                source.addTestSpringFactory?.({
                    key: 'org.springframework.test.context.ContextCustomizerFactory',
                    value: `${application.packageName}.config.PulsarTestContainersSpringContextCustomizerFactory`,
                });
            },
            applyPulsarGradleConventionPlugin({ source, application }) {
                if (application.buildToolGradle) {
                    source.addGradlePlugin?.({ id: 'jhipster.pulsar-conventions' });
                }
            },
            addPulsarMavenDependencies({ application, source }) {
                if (application.buildToolMaven) {
                    const { javaDependencies } = application;
                    source.addMavenDefinition?.({
                        properties: [{ property: 'spring-pulsar.version', value: javaDependencies?.['spring-pulsar'] }],
                        dependencies: [
                            { groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-stream' },
                            { groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-stream-binder-pulsar' },
                            { groupId: 'org.testcontainers', artifactId: 'junit-jupiter', scope: 'test' },
                            { groupId: 'org.testcontainers', artifactId: 'testcontainers', scope: 'test' },
                            { groupId: 'org.testcontainers', artifactId: 'pulsar', scope: 'test' },
                        ],
                    });
                }
            },
        });
    }
    get [BaseApplicationGenerator.POST_WRITING]() {
        return this.delegateTasksToBlueprint(() => this.postWriting);
    }
}
