'use strict';

var map = require('async/map');
var getDagNode = require('./get-dagnode');

// transform { Hash: '...' } objects into { path: 'string', node: DAGNode }
module.exports = function (err, res, send, done) {
  if (err) {
    return done(err);
  }

  map(res, function (entry, next) {
    getDagNode(send, entry.Hash, function (err, node) {
      if (err) {
        return next(err);
      }
      node.size(function (err, size) {
        if (err) {
          return next(err);
        }
        var obj = {
          path: entry.Name,
          hash: entry.Hash,
          size: size
        };
        next(null, obj);
      });
    });
  }, function (err, res) {
    done(err, res);
  });
};