'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    Schema = mongoose.Schema;


/**
 * Team Schema
 */
var TeamSchema = new Schema({
    name: {
        type: String,
        default: '',
        trim: true
    },
    group: {
        type: Schema.ObjectId,
        ref: 'Group'
    },
    players: [{
        type: Schema.ObjectId,
        ref: 'Player'
    }]
});

/**
 * Validations
 */
//TeamSchema.path('title').validate(function (title) {
//    return title.length;
//}, 'Title cannot be blank');

/**
 * Statics
 */
TeamSchema.statics.load = function (id, cb) {
    this.findOne({
        _id: id
    }).populate('players', 'name number').exec(cb);
};

mongoose.model('Team', TeamSchema);
