import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

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

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

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

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