var db = require('./db');
var sendJSON = require('./util/sendJSON');

// Constructor for RestBuilder
function RestBuilder(app) {
  this.app = app;
}

RestBuilder.prototype.defineGetSingle = function(name, model, preprocessors, postprocessors) {
  var route = '/' + name +  '/:id';
  var handlers = preprocessors || [];
  function _getSingle(req, res, next) {
    db.get(model, req.params.id, sendJSON(res, next));
  }
  handlers.push(_getSingle);
  this.app.get(route, handlers);
};

RestBuilder.prototype.defineGetMany = function(name, model, preprocessors, postprocessors) {
  var route = '/' + name;
  var handlers = preprocessors || [];
  function _getMany(req, res, next) {
    db.get(model, req.params.q, sendJSON(res, next));
  }
  handlers.push(_getMany);
  this.app.get(route, handlers);
};

RestBuilder.prototype.definePost = function(name, model, preprocessors, postprocessors) {
  var route = '/' + name;
  var handlers = preprocessors || [];
  function _post(req, res, next) {
    db.add(model, req.body, sendJSON(res, next));
  }
  handlers.push(_post);
  this.app.post(route, handlers);
};

RestBuilder.prototype.definePut = function(name, model, preprocessors, postprocessors) {
  var route = '/' + name +  '/:id';
  var handlers = preprocessors || [];
  function _put(req, res, next) {
    db.update(model, req.params.id, req.params.q, sendJSON(res, next));
  }
  handlers.push(_put);
  this.app.put(route, handlers);
};

RestBuilder.prototype.defineDelete = function(name, model, preprocessors, postprocessors) {
  var route = '/' + name +  '/:id';
  var handlers = preprocessors || [];
  function _del(req, res, next) {
    db.delete(model, req.params.id, sendJSON(res, next));
  }
  handlers.push(_del);
  this.app.del(route, handlers);
  // TODO define deletions of relationships
};

module.exports = RestBuilder;
@@ -190,37 +190,42 @@
  function(name, 
-model
+collection
 , preprocessors,
@@ -360,37 +360,42 @@
 t) %7B%0A    db.get(
-model
+collection
 , req.params.id,
@@ -532,37 +532,42 @@
  function(name, 
-model
+collection
 , preprocessors,
@@ -698,21 +698,26 @@
  db.get(
-model
+collection
 , req.pa
@@ -856,37 +856,42 @@
  function(name, 
-model
+collection
 , preprocessors,
@@ -1019,21 +1019,26 @@
  db.add(
-model
+collection
 , req.bo
@@ -1170,37 +1170,42 @@
  function(name, 
-model
+collection
 , preprocessors,
@@ -1345,21 +1345,26 @@
 .update(
-model
+collection
 , req.pa
@@ -1524,21 +1524,26 @@
 n(name, 
-model
+collection
 , prepro
@@ -1695,13 +1695,18 @@
 ete(
-model
+collection
 , re

Rename model variables to collections