
/**
 * Module dependencies.
 */

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 SectionGrupSchema = new Schema({
  sectionGrup: { type: String, default: '', trim : true , unique: true },
   title: { type: String, default: '', trim : true }
});

/**
 * Validations
 */

SectionGrupSchema.path('sectionGrup').required(true, 'Section grup boş olamaz');


/**
 * Pre-remove hook
 */

SectionGrupSchema.pre('remove', function (next) {
  

  next();
});

/**
 * Methods
 */

SectionGrupSchema.pre('save', function(next) {
  next();
});


SectionGrupSchema.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
 */
SectionGrupSchema.statics = {

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

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

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

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

var SectionGrup = mongoose.model('SectionGrup', SectionGrupSchema);
