'use strict';

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Command = require('ronin').Command;
var utils = require('../../utils');
var bs58 = require('bs58');
var debug = require('debug');
var log = debug('cli:object');
log.error = debug('cli:object:error');

module.exports = Command.extend({
  desc: 'Get stats for the DAG node named by <key>',

  options: {},

  run: function run(key) {
    if (!key) {
      throw new Error("Argument 'key' is required");
    }

    utils.getIPFS(function (err, ipfs) {
      if (err) {
        throw err;
      }
      var mh = utils.isDaemonOn() ? key : new Buffer(bs58.decode(key));

      ipfs.object.stat(mh, function (err, stats) {
        if (err) {
          log.error(err);
          throw err;
        }

        delete stats.Hash; // only for js-ipfs-api output

        (0, _keys2.default)(stats).forEach(function (key) {
          console.log(key + ': ' + stats[key]);
        });
      });
    });
  }
});