// couch/lists.js
//
var guard = require('@holmwell/errors').guard;

module.exports = function (couch) {
    var database = couch.db;

    var addList = function (list, callback) {
        list.type = "list";
        database.insert(list, guard(callback, function (body) {
            list._id = body.id;
            list._rev = body.rev;
            return callback(null, list);
        }));
    };

    var byCircleId = function (circleId, callback) {
        var options = {
            key: circleId
        };
        couch.view("lists/byCircleId", options, callback);
    };

    return {
        add: addList,
        byCircleId: byCircleId
    };
};