package ub.scp2.entities;

import java.util.HashSet;
import java.util.Set;

/**
 * Submission.java -this class is an entity binded to the submission table from the database
 * 
 *
 */
public class Submission implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Long submissionId;
	private Task task;
        private Set<FileSubmission> files;
	private User user;
	private Integer mark;
	private Set<TestResult> testsResult = new HashSet<TestResult>(0);

	public Submission() {
	}

	public Submission(Task task, User user, String output,Set<TestResult> testsResult) {
		this.task = task;
		this.testsResult = testsResult;
	}

	public Long getSubmissionId() {
		return this.submissionId;
	}

	public void setSubmissionId(Long submissionId) {
		this.submissionId = submissionId;
	}

	public Task getTask() {
		return this.task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
        
        public Long getId(){ 
            return submissionId;
        }

	public Integer getMark() {
		return mark;
	}

	public void setMark(Integer mark) {
		this.mark = mark;
	}

	public Set<TestResult> getTestsResult() {
		return testsResult;
	}

	public void setTestsResult(Set<TestResult> testsResult) {
		this.testsResult = testsResult;
	}

        public Set<FileSubmission> getFiles() {
                return files;
        }

        public void setFiles(Set<FileSubmission> files) {
                this.files = files;
        }

        public void addFile(FileSubmission filetask){
            for (FileSubmission f:files){
                if (f.getFilename().equals(filetask.getFilename())){
                    files.remove(f);
                    break;
                }
            }
            files.add(filetask);
        }
        
        public void removeFile(FileSubmission filetask){
            files.remove(filetask);
        }        
        
        public void removeAllFiles(){
            files.removeAll(files);
        }
        
        
	public java.util.ArrayList<String> getFilenameArray(){                
            java.util.ArrayList<String> filenames = new java.util.ArrayList();
            for (FileSubmission fs : this.getFiles())
                    filenames.add(fs.getFilename());
            return filenames;
	}
}
