import { Type } from './Type.js';
import { ValidationError } from '../errors.js';
/** Maps a database TIME column to a JS `string` in HH:MM:SS format. */
export class TimeType extends Type {
  convertToDatabaseValue(value, platform) {
    if (value && !value.toString().match(/^\d{2,}:(?:[0-5]\d):(?:[0-5]\d)$/)) {
      throw ValidationError.invalidType(TimeType, value, 'JS');
    }
    return super.convertToDatabaseValue(value, platform);
  }
  compareAsType() {
    return 'string';
  }
  ensureComparable() {
    return false;
  }
  getColumnType(prop, platform) {
    return platform.getTimeTypeDeclarationSQL(prop.length);
  }
  getDefaultLength(platform) {
    return platform.getDefaultDateTimeLength();
  }
}
