import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

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

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

  constructor(params: InvalidLeagueSettingsSchemaErrorParams);
  constructor(message: string);
  constructor(paramsOrMessage: InvalidLeagueSettingsSchemaErrorParams | string) {
    if (typeof paramsOrMessage === 'string') {
      super({
        entityName: 'League',
        fieldName: 'settings',
        reason: 'invalid_shape',
        message: paramsOrMessage,
      });
      return;
    }

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