import { TypeOrmPersistenceSchemaError } from './TypeOrmPersistenceSchemaError';

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

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

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