import path from 'path';
import { camelCase } from 'lodash-es';
import { isReproducible } from '../../base/support/index.js';
const defaultName = 'jhipster';
export const validateJavaApplicationName = (name) => {
    if (!/^([\w]*)$/.test(name)) {
        return 'Your base name cannot contain special characters or a blank space';
    }
    if (/_/.test(name)) {
        return 'Your base name cannot contain underscores as this does not meet the URI spec';
    }
    if (name.toLowerCase() === 'application') {
        return "Your base name cannot be named 'application' as this is a reserved name for Spring Boot";
    }
    return true;
};
export const validateNpmProjectName = (name) => {
    if (!/^([\w-.]*)$/.test(name)) {
        return 'Your base name cannot contain special characters or a blank space';
    }
    return true;
};
export const validateProjectName = (name, { javaApplication } = {}) => javaApplication ? validateJavaApplicationName(name) : validateNpmProjectName(name);
const getDefaultName = (generator) => {
    if (generator?.options && isReproducible(generator)) {
        return defaultName;
    }
    let projectName = path.basename(process.cwd());
    const { reproducible = false, javaApplication = false } = generator && !generator.options ? generator : {};
    if (reproducible) {
        return defaultName;
    }
    if (javaApplication) {
        projectName = camelCase(projectName);
    }
    else {
        projectName = projectName.replace('generator-jhipster-', '');
    }
    return validateProjectName(projectName, { javaApplication }) === true ? projectName : defaultName;
};
export default getDefaultName;
