import { javaMainPackageTemplatesBlock } from '../java/support/index.mjs';
const sqlFiles = {
    sqlFiles: [
        {
            condition: generator => !generator.reactive,
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: ['domain/_persistClass_.java.jhi.jakarta_persistence'],
        },
        {
            condition: generator => !generator.reactive && generator.requiresPersistableImplementation,
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: ['domain/_persistClass_.java.jhi.jakarta_lifecycle_events'],
        },
        {
            condition: generator => !generator.reactive && generator.enableHibernateCache && generator.ormTool === 'hibernate',
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: ['domain/_persistClass_.java.jhi.hibernate_cache'],
        },
        {
            condition: generator => !generator.reactive && !generator.embedded && generator.containsBagRelationships && generator.ormTool === 'hibernate',
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: [
                'repository/_entityClass_RepositoryWithBagRelationships.java',
                'repository/_entityClass_RepositoryWithBagRelationshipsImpl.java',
            ],
        },
        {
            condition: generator => generator.reactive,
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: ['domain/_persistClass_.java.jhi.spring_data_reactive'],
        },
        {
            condition: generator => generator.requiresPersistableImplementation,
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: ['domain/_persistClass_.java.jhi.spring_data_persistable'],
        },
        {
            condition: generator => generator.reactive && generator.requiresPersistableImplementation,
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: ['domain/_persistClass_Callback.java'],
        },
        {
            condition: generator => generator.reactive && !generator.embedded,
            ...javaMainPackageTemplatesBlock('_entityPackage_'),
            templates: [
                'repository/_entityClass_RepositoryInternalImpl_reactive.java',
                'repository/_entityClass_SqlHelper_reactive.java',
                'repository/rowmapper/_entityClass_RowMapper_reactive.java',
            ],
        },
    ],
};
export function cleanupEntitiesTask() { }
export default async function writeEntitiesTask({ application, entities }) {
    for (const entity of entities.filter(entity => !entity.skipServer)) {
        if (entity.builtInUser) {
            await this.writeFiles({
                blocks: [
                    {
                        condition: generator => generator.reactive && generator.requiresPersistableImplementation,
                        ...javaMainPackageTemplatesBlock('_entityPackage_'),
                        templates: ['domain/_persistClass_Callback.java'],
                    },
                ],
                context: { ...application, ...entity },
            });
        }
        else if (!entity.builtIn) {
            await this.writeFiles({
                sections: sqlFiles,
                context: { ...application, ...entity },
            });
        }
    }
}
