import { asWriteFilesSection } from '../base-application/support/index.js';
import { LOCAL_BLUEPRINT_OPTION } from './constants.js';
export const files = asWriteFilesSection({
    baseFiles: [
        {
            condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION],
            templates: [
                '.github/workflows/generator.yml',
                '.gitignore.jhi.blueprint',
                '.prettierignore.jhi.blueprint',
                { sourceFile: 'eslint.config.js.jhi.blueprint', destinationFile: ctx => `${ctx.eslintConfigFile}.jhi.blueprint` },
                'README.md',
                'tsconfig.json',
                'vitest.config.ts',
                'vitest.test-setup.ts',
                '.blueprint/cli/commands.mjs',
                '.blueprint/generate-sample/command.mjs',
                '.blueprint/generate-sample/generator.mjs',
                '.blueprint/generate-sample/index.mjs',
                'cli/cli.cjs',
                { sourceFile: 'cli/cli-customizations.cjs', override: false },
            ],
        },
        {
            condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && ctx.githubWorkflows,
            templates: [
                '.blueprint/github-build-matrix/command.mjs',
                '.blueprint/github-build-matrix/generator.mjs',
                '.blueprint/github-build-matrix/generator.spec.mjs',
                '.blueprint/github-build-matrix/index.mjs',
            ],
        },
        {
            condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && ctx.githubWorkflows && !ctx.skipWorkflows,
            templates: ['.github/workflows/build-cache.yml', '.github/workflows/samples.yml'],
        },
        {
            condition: ctx => !ctx[LOCAL_BLUEPRINT_OPTION] && !ctx.sampleWritten,
            templates: ['.blueprint/generate-sample/templates/samples/sample.jdl'],
        },
        {
            condition: ctx => ctx.commands.length > 0,
            templates: ['cli/commands.cjs'],
        },
    ],
});
export const generatorFiles = asWriteFilesSection({
    generator: [
        {
            path: 'generators/generator',
            to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
            templates: [
                { sourceFile: 'index.mjs', destinationFile: ctx => `index.${ctx.blueprintMjsExtension}` },
                {
                    sourceFile: 'command.mjs',
                    destinationFile: ctx => `command.${ctx.blueprintMjsExtension}`,
                    override: data => !data.ignoreExistingGenerators,
                },
                {
                    sourceFile: 'generator.mjs.jhi',
                    destinationFile: ctx => `generator.${ctx.blueprintMjsExtension}.jhi`,
                    override: data => !data.ignoreExistingGenerators,
                },
                {
                    condition: data => !data.generator.startsWith('entity') && !data.application[LOCAL_BLUEPRINT_OPTION],
                    sourceFile: 'generator.spec.mjs',
                    destinationFile: data => `generator.spec.${data.blueprintMjsExtension}`,
                    override: data => !data.ignoreExistingGenerators,
                },
            ],
        },
        {
            path: 'generators/generator',
            to: ctx => `${ctx.application.blueprintsPath}${ctx.generator}`,
            condition(ctx) {
                return !ctx.written && ctx.priorities.find(priority => priority.name === 'writing');
            },
            transform: false,
            templates: [
                {
                    sourceFile: 'templates/template-file.ejs',
                    destinationFile: ctx => `templates/template-file-${ctx.generator}.ejs`,
                },
            ],
        },
    ],
});
