import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

type InvalidRaceSessionTypeSchemaErrorParams = {
  fieldName: string;
  reason: TypeOrmPersistenceSchemaError['reason'];
  message?: string;
};

export class InvalidRaceSessionTypeSchemaError extends TypeOrmPersistenceSchemaError {
  override readonly name: string = 'InvalidRaceSessionTypeSchemaError';

  constructor(params: InvalidRaceSessionTypeSchemaErrorParams);
  constructor(message: string);
  constructor(paramsOrMessage: InvalidRaceSessionTypeSchemaErrorParams | string) {
    if (typeof paramsOrMessage === 'string') {
      super({
        entityName: 'Race',
        fieldName: 'sessionType',
        reason: 'invalid_shape',
        message: paramsOrMessage,
      });
      return;
    }

    super({
      entityName: 'Race',
      fieldName: paramsOrMessage.fieldName,
      reason: paramsOrMessage.reason,
      ...(paramsOrMessage.message ? { message: paramsOrMessage.message } : {}),
    });
  }
}