import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

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

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

  constructor(params: InvalidLeagueScoringConfigChampionshipsSchemaErrorParams);
  constructor(message?: string);
  constructor(paramsOrMessage: InvalidLeagueScoringConfigChampionshipsSchemaErrorParams | string | undefined) {
    if (typeof paramsOrMessage === 'string' || paramsOrMessage === undefined) {
      super({
        entityName: 'LeagueScoringConfig',
        fieldName: 'championships',
        reason: 'invalid_shape',
        ...(paramsOrMessage ? { message: paramsOrMessage } : {}),
      });
      return;
    }

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