package net.sourceforge.jsurveyor;
import java.util.*;

/**
 * This is a container class to handle a users submitted answers for a questionnaire. 
 * It holds references to the user that has submitted the evaluation, reference to the questionnaire, a timestampt and a list of the answers contained in the evaluation.
 * @version 1.0
 * @author Claus Methmann Christensen
 * @author Anders Spliid Hansen
 * @author Esben Iversen Hansen
 * @author Lars H Jensen
 * @author Marcus Overheu
 * @author Thomas Ramdal
 * @author Peter Thomsen
 */

public class Evaluation {
	
	/**
	 * Field evaluationID
	 */
	private int evaluationID;
	/**
	 * Field userName
	 */
	private String userName;
	/**
	 * Field timestamp
	 */
	private Date timestamp;
	/**
	 * Field questionnaireID
	 */
	private int questionnaireID;
	/**
	 * Field answers
	 */
	private ArrayList answers = new ArrayList();

	/**
	 * Constructor for Evaluation
	 */
	public Evaluation() {
		this.timestamp = new Date();
	}
	
	/**
	 * Constructor for Evaluation
	 * @param userName String
	 * @param questionnaireID int
	 */
	public Evaluation(String userName, int questionnaireID) {
		assert(
			questionnaireID
				!= 0) : "the questionnaire attached to the evaluation must have an ID";
		assert(
			userName
				!= null) : "There must be a user attached to the evaluation";
		this.userName = userName;
		this.timestamp = new Date();
		this.questionnaireID = questionnaireID;
	}

	/**
	 * Constructor for Evaluation
	 * @param evaluationID int
	 * @param userName String
	 * @param questionnaireID int
	 */
	public Evaluation(int evaluationID, String userName, int questionnaireID) {
		assert(evaluationID != 0) : "the evaluation must have an ID";
		assert(
			questionnaireID
				!= 0) : "the questionnaire attached to the evaluation must have an ID";
		assert(
			userName
				!= null) : "There must be a user attached to the evaluation";
		this.evaluationID = evaluationID;
		this.userName = userName;
		this.timestamp = new Date();
		this.questionnaireID = questionnaireID;
	}

	/**
	 * Constructor for Evaluation, usage only through DataAccess.
	 * @param evaluationID int
	 * @param userName String
	 * @param questionnaireID int
	 * @param date long
	 * @param answers ArrayList
	 */
	public Evaluation(
		int evaluationID,
		String userName,
		int questionnaireID,
		long date, ArrayList answers) {
		assert(evaluationID != 0) : "the evaluation must have an ID";
		assert(
			questionnaireID
				!= 0) : "the questionnaire attached to the evaluation must have an ID";
		assert(
			userName
				!= null) : "There must be a user attached to the evaluation";
		this.evaluationID = evaluationID;
		this.userName = userName;
		this.timestamp = new Date(date);
		this.questionnaireID = questionnaireID;
		this.answers = answers;
	}

	/**
	 * Sets an ID for the evaluation.
	 * @param evaluationID int
	 */
	public void setEvaluationID(int evaluationID) {
		assert(evaluationID != 0) : "the evaluation must have an ID";
		this.evaluationID = evaluationID;
	}

	/**
	 * Returns the evaluations ID.
	 * @return int
	 */
	public int getEvaluationID() {
		return evaluationID;
	}

	/**
	 * Sets the name of the person who has submitted the evaluation.
	 * @param userNameInput String
	 */
	public void setUserName(String userNameInput) {
		assert(userNameInput != null) : "no users name is registered";
		userName = userNameInput;
	}

	/**
	 * Returns the username of the person that has submitted this evaluation.
	 * @return String
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * Sets a timestampt for the object. 
	 * The timestampt represents when the evaluation has been submitted.
	 * @param timestamp Date
	 */
	public void setTimestamp(Date timestamp) {
		this.timestamp = timestamp;
	}
	/**
	 * Returns the timestamp of the object.
	 * The timestampt represents when the evaluation has been submitted.
	 * @return Date
	 */
	public long getTimestamp() {
		return timestamp.getTime();
	}

	/**
	 * Sets the questionnaire that this is an evaluation for.
	 * @param questionnaireID int
	 */
	public void setQuestionnaireID(int questionnaireID) {
		this.questionnaireID = questionnaireID;
	}

	/**
	 * Returns an id of the questionnaire that this is an evaluation for.
	 * @return int
	 */
	public int getQuestionnaireID() {
		return questionnaireID;
	}
	
	/**
	 * Returns an ArrayList containing toString representations of all the answers in the evaluation
	 * @return ArrayList
	 */
	public ArrayList getAnswers() {
		return answers;
	}
	
	/**
	 * Adds an answer to the evaluation 
	 * @param answer Answer
	 */
	public void addAnswer(Answer answer) {
		answers.add(answer.toString());
	}
	
	/**
	 * 
	 *Returns the number of answers 
	 *
	 */
	public int getAnswerSize(){
		return answers.size();
	}
	
}
