import { HttpException, HttpStatus } from '@nestjs/common';

export class BlockchainException extends HttpException {
  constructor(
    message: string,
    public readonly chainType?: string,
    public readonly txHash?: string,
    status: HttpStatus = HttpStatus.SERVICE_UNAVAILABLE,
  ) {
    super(
      {
        statusCode: status,
        error: 'Blockchain Error',
        message,
        chainType,
        txHash,
      },
      status,
    );
  }
}

export class RpcConnectionException extends BlockchainException {
  constructor(chainType: string, message: string = 'RPC connection failed') {
    super(message, chainType, undefined, HttpStatus.SERVICE_UNAVAILABLE);
  }
}

export class TransactionFailedException extends BlockchainException {
  constructor(chainType: string, txHash: string, message: string = 'Transaction failed') {
    super(message, chainType, txHash, HttpStatus.UNPROCESSABLE_ENTITY);
  }
}

export class InvalidAddressException extends BlockchainException {
  constructor(address: string) {
    super(`Invalid address: ${address}`, undefined, undefined, HttpStatus.BAD_REQUEST);
  }
}
