import { SERVER_TEST_SRC_DIR, SERVER_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR, SERVER_TEST_RES_DIR } from '../../generator-constants.mjs';
export const replaceEntityFilePathVariables = (data, filePath) => {
    filePath = filePath
        ?.replace(/_package_/, data.packageFolder)
        ?.replace(/_entityPackage_/, data.entityJavaPackageFolder)
        ?.replace(/_mainClass_/, data.mainClass)
        ?.replace(/_persistClass_/, data.persistClass)
        ?.replace(/_entityClass_/, data.entityClass)
        ?.replace(/_dtoClass_/, data.dtoClass);
    return filePath?.includes('.jhi.') ? filePath : filePath?.replace(/_\w*/, '');
};
export const moveToJavaPackageSrcDir = (data, filePath) => `${data.javaPackageSrcDir}${replaceEntityFilePathVariables(data, filePath) ?? ''}`;
export const moveToJavaPackageTestDir = (data, filePath) => `${data.javaPackageTestDir}${replaceEntityFilePathVariables(data, filePath) ?? ''}`;
export const moveToJavaEntityPackageSrcDir = (data, filePath) => `${data.srcMainJava}${data.entityAbsoluteFolder}${replaceEntityFilePathVariables(data, filePath) ?? ''}`;
export const moveToJavaEntityPackageTestDir = (data, filePath) => `${data.srcTestJava}${data.entityAbsoluteFolder}${replaceEntityFilePathVariables(data, filePath) ?? ''}`;
export const moveToSrcMainResourcesDir = (data, filePath) => `${data.srcMainResources}${replaceEntityFilePathVariables(data, filePath) ?? ''}`;
export const moveToSrcTestResourcesDir = (data, filePath) => `${data.srcTestResources}${replaceEntityFilePathVariables(data, filePath) ?? ''}`;
export function javaMainPackageTemplatesBlock(blockOrRelativePath = '') {
    return javaBlock({
        srcPath: `${SERVER_MAIN_SRC_DIR}_package_/`,
        destProperty: 'javaPackageSrcDir',
        blockOrRelativePath,
    });
}
export function javaMainResourceTemplatesBlock(blockOrRelativePath = '') {
    return javaBlock({
        srcPath: SERVER_MAIN_RES_DIR,
        destProperty: 'srcMainResources',
        blockOrRelativePath,
    });
}
export function javaTestResourceTemplatesBlock(blockOrRelativePath = '') {
    return javaBlock({
        srcPath: SERVER_TEST_RES_DIR,
        destProperty: 'srcTestResources',
        blockOrRelativePath,
    });
}
export function javaTestPackageTemplatesBlock(blockOrRelativePath = '') {
    return javaBlock({
        srcPath: `${SERVER_TEST_SRC_DIR}_package_/`,
        destProperty: 'javaPackageTestDir',
        blockOrRelativePath,
    });
}
function javaBlock({ srcPath, destProperty, blockOrRelativePath = '', }) {
    const block = typeof blockOrRelativePath !== 'string' ? blockOrRelativePath : undefined;
    const blockRenameTo = typeof block?.renameTo === 'function' ? block.renameTo : undefined;
    const relativePath = typeof blockOrRelativePath === 'string' ? blockOrRelativePath : blockOrRelativePath.relativePath ?? '';
    return {
        path: `${srcPath}${relativePath}`,
        ...block,
        renameTo(data, filePath) {
            return `${data[destProperty]}${replaceEntityFilePathVariables(data, relativePath) ?? ''}${replaceEntityFilePathVariables(data, blockRenameTo?.call?.(this, data, filePath) ?? filePath) ?? ''}`;
        },
    };
}
