import { asPostWritingEntitiesTask, asWritingEntitiesTask } from '../base-application/support/index.js';
import { clientApplicationTemplatesBlock } from '../client/support/index.js';
export const entityFiles = {
    client: [
        clientApplicationTemplatesBlock({
            relativePath: 'shared/model/',
            templates: ['_entityModel_.model.ts'],
        }),
        {
            condition: generator => !generator.embedded,
            ...clientApplicationTemplatesBlock(),
            templates: [
                'entities/_entityFolder_/_entityFile_-details.vue',
                'entities/_entityFolder_/_entityFile_-details.component.ts',
                'entities/_entityFolder_/_entityFile_-details.component.spec.ts',
                'entities/_entityFolder_/_entityFile_.vue',
                'entities/_entityFolder_/_entityFile_.component.ts',
                'entities/_entityFolder_/_entityFile_.component.spec.ts',
                'entities/_entityFolder_/_entityFile_.service.ts',
                'entities/_entityFolder_/_entityFile_.service.spec.ts',
            ],
        },
        {
            condition: generator => !generator.readOnly && !generator.embedded,
            ...clientApplicationTemplatesBlock(),
            templates: [
                'entities/_entityFolder_/_entityFile_-update.vue',
                'entities/_entityFolder_/_entityFile_-update.component.ts',
                'entities/_entityFolder_/_entityFile_-update.component.spec.ts',
            ],
        },
    ],
};
export const writeEntityFiles = asWritingEntitiesTask(async function writeEntityFiles({ control, application, entities }) {
    for (const entity of (control.filterEntitiesAndPropertiesForClient ?? (entities => entities))(entities).filter(entity => !entity.skipClient && !entity.builtInUser)) {
        await this.writeFiles({
            sections: entityFiles,
            context: { ...application, ...entity },
        });
    }
});
export const postWriteEntityFiles = asPostWritingEntitiesTask(async function postWriteEntityFiles({ control, application, entities }) {
    for (const entity of (control.filterEntitiesForClient ?? (entities => entities))(entities).filter(entity => !entity.builtInUser)) {
        if (!entity.embedded) {
            const { enableTranslation } = application;
            const { entityInstance, entityClass, entityAngularName, entityFolderName, entityFileName, entityUrl, microserviceName, readOnly, entityClassPlural, i18nKeyPrefix, } = entity;
            const pageTitle = (entity.pageTitle ?? enableTranslation) ? `${i18nKeyPrefix}.home.title` : entityClassPlural;
            this.addEntityToModule(entityInstance, entityClass, entityAngularName, entityFolderName, entityFileName, entityUrl, microserviceName, readOnly, pageTitle);
            this.addEntityToMenu(entity.entityPage, application.enableTranslation, entity.entityTranslationKeyMenu, entity.entityClassHumanized);
        }
    }
});
export const cleanupEntitiesFiles = asWritingEntitiesTask(function cleanupEntitiesFiles({ control, application, entities }) {
    for (const entity of (control.filterEntitiesForClient ?? (entities => entities))(entities).filter(entity => !entity.builtInUser)) {
        const { entityFolderName, entityFileName } = entity;
        if (this.isJhipsterVersionLessThan('8.0.0-beta.3')) {
            this.removeFile(`${application.clientTestDir}/spec/app/entities/${entityFolderName}/${entityFileName}.component.spec.ts`);
            this.removeFile(`${application.clientTestDir}/spec/app/entities/${entityFolderName}/${entityFileName}-detail.component.spec.ts`);
            this.removeFile(`${application.clientTestDir}/spec/app/entities/${entityFolderName}/${entityFileName}-update.component.spec.ts`);
            this.removeFile(`${application.clientTestDir}/spec/app/entities/${entityFolderName}/${entityFileName}.service.spec.ts`);
        }
    }
});
