import BaseApplicationGenerator from '../base-application/index.js';
import { feignFiles } from './files.js';
import cleanupTask from './cleanup.js';
export default class FeignClientGenerator extends BaseApplicationGenerator {
    async beforeQueue() {
        if (!this.fromBlueprint) {
            await this.composeWithBlueprints();
        }
        if (!this.delegateToBlueprint) {
            await this.dependsOnBootstrapApplication();
        }
    }
    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.delegateTasksToBlueprint(() => this.postWriting);
    }
}
