var mongoose = require('mongoose');
var Imager = rekuire('imager');
var config = rekuire('config');
var imagerConfig = rekuire(config.root + '/config/imager.js');
var utils = require('../../lib/utils')


var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
/**
 * Getters 
 */

var getTags = function (tags) {
  return tags.join(',');  
};

/**
 * Setters
 */

var setTags = function (tags) {
  return tags.split(',');
};

/**
 * Article Schema
 */

var DocumentSchema = new Schema({
  name: { type: String, default: '', trim : true  }
});

DocumentSchema.path('name').required(true, 'Ad boş olamaz');


DocumentSchema.methods = {

  /**
   * Save article and upload image
   *
   * @param {Object} images
   * @param {Function} cb
   * @api private
   */

  canSeeByUser: function(user){
    return true;
  },
  canEditByUser: function(user) {
    
      return true;
  },

  
};

/**
 * Statics
 */
DocumentSchema.statics = {

  /**
   * Find article by id
   *
   * @param {ObjectId} id
   * @param {Function} cb
   * @api private
   */
load: function (id, cb) {
    this.findOne({_id: id})
      .select('name')
      .exec(cb);
  },
  load2: function (options, cb) {
    options.select = options.select || 'name';
    this.find(options.criteria)
      .select(options.select)
      .sort({ 'name' : 1})
      .exec(cb);
  },


  /**
   * List articles
   *
   * @param {Object} options
   * @param {Function} cb
   * @api private
   */

  list: function (options, cb) {
    var criteria = options.criteria || {}

    this.find(criteria)
      .sort({ 'name' : 1}) // sort by date
      .limit(options.perPage)
      .skip(options.perPage * options.page)
      .exec(cb);
  },
  
  
}

var Document = mongoose.model('Document', DocumentSchema);