'use strict';

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

/**
 * A Validation function for headlines
 */
var validateHeadline = function(headline) {
	return (headline.length <= 90);
};

/**
 * A Validation function for descriptions
 */
var validateDescription = function(description) {
	return (description.length <= 141);
};

/*
* Response Schema
*/
var ResponseSchema = new Schema({
    answerIds: {
        type: [Number]
    },
    answerText: {
        type: String
    },
    user: {
        type: Schema.ObjectId,
        ref: 'User'
    },
    created: {
        type: Date,
        default: Date.now
    }
});

/*
* Question Schema
*/
var QuestionSchema = new Schema({
	text: {
		type: String,
		default: '',
		required: 'Please fill question',
		trim: true
	},
	type: {
		type: String,
		required: 'Please select question type'
	},
    startValue: {
        type: String,
        trim: true
    },
    endValue: {
        type: String,
        trim: true
    },
    responseData: [{
        text: String
    }],
    responses: [ResponseSchema]
});

/**
 * Project Schema
 */
var ProjectSchema = new Schema({
	headline: {
		type: String,
		default: '',
		required: 'Please fill project headline',
		validate: [validateHeadline, 'Headline is longer than 90 characters'],
		trim: true
	},
	description: {
		type: String,
		default: '',
		required: 'Please fill project description',
		validate: [validateDescription, 'Description is longer than 141 characters'],
		trim: true
	},
	closed: {
		type: Boolean,
		default: false
	},
	questions: [QuestionSchema],
	user: {
		type: Schema.ObjectId,
		ref: 'User'
	},
    updated: {
        type: Date
    },
    created: {
        type: Date,
        default: Date.now
    }
});

mongoose.model('Project', ProjectSchema);

@@ -373,16 +373,268 @@
 1);%0A%7D;%0A%0A
+/*%0A* Comment Schema%0A*/%0Avar CommentSchema = new Schema(%7B%0A    text: %7B%0A        type: String,%0A%09%09trim: true%0A    %7D,%0A    user: %7B%0A        type: Schema.ObjectId,%0A        ref: 'User'%0A    %7D,%0A    created: %7B%0A        type: Date,%0A        default: Date.now%0A    %7D%0A%7D);%0A%0A
 /*%0A* Res
@@ -1864,16 +1864,45 @@
 chema%5D,%0A
+%09comments: %5BCommentSchema%5D,%09%0A
 %09user: %7B

add comment model