import { ShadeError } from '@shade/core';

export class TransferError extends ShadeError {
  constructor(code: string, message: string) {
    super(code, message);
    this.name = 'TransferError';
  }
}

export class TransferAbortError extends TransferError {
  constructor(message = 'Transfer aborted') {
    super('SHADE_TRANSFER_ABORT', message);
    this.name = 'TransferAbortError';
  }
}

export class TransferIntegrityError extends TransferError {
  constructor(message: string) {
    super('SHADE_TRANSFER_INTEGRITY', message);
    this.name = 'TransferIntegrityError';
  }
}

export class TransferProtocolError extends TransferError {
  constructor(message: string) {
    super('SHADE_TRANSFER_PROTOCOL', message);
    this.name = 'TransferProtocolError';
  }
}

export class TransferOfflineError extends TransferError {
  constructor(peer: string, message?: string) {
    super(
      'SHADE_TRANSFER_OFFLINE',
      message ?? `Peer ${peer} is offline. Queue/relay support deferred to a later version.`,
    );
    this.name = 'TransferOfflineError';
  }
}

export class TransferResumeError extends TransferError {
  constructor(message: string) {
    super('SHADE_TRANSFER_RESUME', message);
    this.name = 'TransferResumeError';
  }
}

export class TransferTransportError extends TransferError {
  constructor(message: string, public readonly statusCode?: number) {
    super('SHADE_TRANSFER_TRANSPORT', message);
    this.name = 'TransferTransportError';
  }
}
