var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    ObjectId = Schema.ObjectId;




var Activity = new Schema({    
    tag : { type : ObjectId, ref: 'Tag' },
    start : { type : Date, default : Date.now, required: true },
    finish : { type : Date, required: true },
    is_manual : { type : Boolean, required: true, default: false },
    created_at : { type: Date, default : Date.now },
    updated_at : { type: Date }
});



Activity.pre('save', function(next){
  now = new Date();
 
  if ( !this.created_at )
    this.created_at = now;  

  if(this.created_at)
     this.updated_at = now;

  next();
});



module.exports = mongoose.model('Activity', Activity);