import BaseApplicationGenerator from '../base-application/index.mjs';
import { GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_FEIGN_CLIENT } from '../generator-list.mjs';
import { feignFiles } from './files.mjs';
import cleanupTask from './cleanup.mjs';
export default class FeignClientGenerator extends BaseApplicationGenerator {
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints(GENERATOR_FEIGN_CLIENT);
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
        }
    }
    get writing() {
        return this.asWritingTaskGroup({
            cleanupTask,
            async writeTask({ application }) {
                await this.writeFiles({
                    sections: feignFiles,
                    context: application,
                });
            },
        });
    }
    get [BaseApplicationGenerator.WRITING]() {
        return this.delegateTasksToBlueprint(() => this.writing);
    }
    get postWriting() {
        return this.asPostWritingTaskGroup({
            addDependencies({ application, source }) {
                const openFeignArtifact = { groupId: 'org.springframework.cloud', artifactId: 'spring-cloud-starter-openfeign' };
                if (application.buildToolMaven) {
                    source.addMavenDependency?.(openFeignArtifact);
                }
                if (application.buildToolGradle) {
                    source.addGradleDependency?.({
                        ...openFeignArtifact,
                        scope: 'implementation',
                    });
                }
            },
        });
    }
    get [BaseApplicationGenerator.POST_WRITING]() {
        return this.asPostWritingTaskGroup(this.delegateTasksToBlueprint(() => this.postWriting));
    }
}
