import { AbstractNamingStrategy } from './AbstractNamingStrategy.js';
/** Naming strategy that converts camelCase names to snake_case for table and column names. */
export class UnderscoreNamingStrategy extends AbstractNamingStrategy {
  classToTableName(entityName, tableName) {
    return tableName ?? this.underscore(entityName);
  }
  joinColumnName(propertyName) {
    return this.underscore(propertyName) + '_' + this.referenceColumnName();
  }
  joinKeyColumnName(entityName, referencedColumnName, composite, tableName) {
    return this.classToTableName(entityName, tableName) + '_' + (referencedColumnName || this.referenceColumnName());
  }
  joinTableName(sourceEntity, targetEntity, propertyName, tableName) {
    return this.classToTableName(sourceEntity, tableName) + '_' + this.classToTableName(propertyName);
  }
  propertyToColumnName(propertyName, object) {
    return this.underscore(propertyName);
  }
  referenceColumnName() {
    return 'id';
  }
  underscore(name) {
    return name.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
  }
}
