import { fieldTypes, databaseTypes } from '../../../../jdl/jhipster/index.mjs';
const dbTypes = fieldTypes;
const { STRING, UUID, LONG, INTEGER } = dbTypes.CommonDBTypes;
const { SQL } = databaseTypes;
export const getJavaValueGeneratorForType = (type) => {
    if (type === STRING) {
        return 'UUID.randomUUID().toString()';
    }
    if (type === UUID) {
        return 'UUID.randomUUID()';
    }
    if (type === LONG || type === INTEGER) {
        return 'count.incrementAndGet()';
    }
    throw new Error(`Java type ${type} does not have a random generator implemented`);
};
export const getPrimaryKeyValue = (primaryKey, databaseType, defaultValue = 1) => {
    if (typeof primaryKey === 'object' && primaryKey.composite) {
        return `new ${primaryKey.type}(${primaryKey.references
            .map(ref => getPrimaryKeyValue(ref.type, databaseType, defaultValue))
            .join(', ')})`;
    }
    const primaryKeyType = typeof primaryKey === 'string' ? primaryKey : primaryKey.type;
    if (primaryKeyType === STRING) {
        if (databaseType === SQL && defaultValue === 0) {
            return getJavaValueGeneratorForType(primaryKeyType);
        }
        return `"id${defaultValue}"`;
    }
    if (primaryKeyType === UUID) {
        return getJavaValueGeneratorForType(primaryKeyType);
    }
    return `${defaultValue}L`;
};
