import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

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

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

  constructor(params: InvalidRaceRegistrationSchemaErrorParams);
  constructor(message: string);
  constructor(paramsOrMessage: InvalidRaceRegistrationSchemaErrorParams | string) {
    super(
      typeof paramsOrMessage === 'string'
        ? {
            entityName: 'RaceRegistration',
            fieldName: 'unknown',
            reason: 'invalid_shape',
            message: paramsOrMessage,
          }
        : {
            entityName: 'RaceRegistration',
            fieldName: paramsOrMessage.fieldName,
            reason: paramsOrMessage.reason,
            ...(paramsOrMessage.message ? { message: paramsOrMessage.message } : {}),
          },
    );
    this.name = 'InvalidRaceRegistrationSchemaError';
  }
}