package org.yacos.core.conferences;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.yacos.core.article.Article;
import org.yacos.core.evaluation.Criterion;
import org.yacos.core.users.Role;


@Entity
public class Conference implements Serializable{
	
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer id;
	private String title;
	private String description;
	private String otherInformations;
	@Temporal(TemporalType.DATE)
	private Date dateAbstract;
	@Temporal(TemporalType.DATE)
	private Date dateArticle;
	@Temporal(TemporalType.DATE)
	private Date dateEvaluation;
	@Temporal(TemporalType.DATE)
	private Date dateStart;
	@Temporal(TemporalType.DATE)
	private Date dateEnd;
	
	/**
	 * Roles of users for this conference 
	 */
	@OneToMany(targetEntity=Role.class,mappedBy="conference")
	private List<Role> roles;
	
/*	@OneToOne(targetEntity=User.class,optional=true)
	@JoinColumn(name="chairman_id",nullable=true)
	private User chairman;
*/	
	@OneToMany(targetEntity=Article.class,mappedBy="conference")
	private List<Article> articles;
	
	@OneToMany(targetEntity=Criterion.class,mappedBy="conference",cascade=CascadeType.ALL)
	private List<Criterion> criterions;
	
	/*
	/**
	 * @return the chairman
	 */
	/*
	@OneToOne(targetEntity=User.class,optional=true)
	@JoinColumn(name="chairman_id",nullable=true)
	public User getChairman() {
		return chairman;
	}
*/
	/**
	 * @param chairman the chairman to set
	 */
/*
	@OneToOne(targetEntity=User.class,optional=true)
	@JoinColumn(name="chairman_id",nullable=true)
	public void setChairman(User chairman) {
		this.chairman = chairman;
	}
*/
	@Temporal(TemporalType.DATE)
    public Date getDateAbstract() {
		return dateAbstract;
	}
	@Temporal(TemporalType.DATE)
	public void setDateAbstract(Date dateAbstract) {
		this.dateAbstract = dateAbstract;
	}
	@Temporal(TemporalType.DATE)
	public Date getDateArticle() {
		return dateArticle;
	}
	@Temporal(TemporalType.DATE)
	public void setDateArticle(Date dateArticle) {
		this.dateArticle = dateArticle;
	}
	@Temporal(TemporalType.DATE)
	public Date getDateEnd() {
		return dateEnd;
	}
	@Temporal(TemporalType.DATE)
	public void setDateEnd(Date dateEnd) {
		this.dateEnd = dateEnd;
	}
	@Temporal(TemporalType.DATE)
	public Date getDateEvaluation() {
		return dateEvaluation;
	}
	@Temporal(TemporalType.DATE)
	public void setDateEvaluation(Date dateEvaluation) {
		this.dateEvaluation = dateEvaluation;
	}
	@Temporal(TemporalType.DATE)
	public Date getDateStart() {
		return dateStart;
	}
	@Temporal(TemporalType.DATE)
	public void setDateStart(Date dateStart) {
		this.dateStart = dateStart;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String descirption) {
		this.description = descirption;
	}
	public String getOtherInformations() {
		return otherInformations;
	}
	public void setOtherInformations(String otherInformations) {
		this.otherInformations = otherInformations;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Integer getId() {
		return id;
	}
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public void setId(Integer id) {
		this.id = id;
	}
	
	public Conference() {
		this.roles = new ArrayList<Role>();
	}
	
	public Conference(String titre, String descirption, String infoComplementray, Date dateAbstract, Date dateArticle, Date dateEvaluation, Date dateStart, Date dateEnd) {
		this();
		this.title = titre;
		this.description = descirption;
		this.otherInformations = infoComplementray;
		this.dateAbstract = dateAbstract;
		this.dateArticle = dateArticle;
		this.dateEvaluation = dateEvaluation;
		this.dateStart = dateStart;
		this.dateEnd = dateEnd;
	}

	/*
	 * articles
	 */
	@OneToMany(targetEntity=Article.class,mappedBy="conference")
	public void setArticles(List<Article> articles) {
		this.articles = articles;
	}
	
	@OneToMany(targetEntity=Article.class,mappedBy="conference")
	public List<Article> getArticles() {
		return articles;
	}

	/*
	 * roles
	 */
	@OneToMany(targetEntity=Role.class,mappedBy="conference")
	public List<Role> getRoles() {
		return roles;
	}

	@OneToMany(targetEntity=Role.class,mappedBy="conference")
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

	/*
	 * criterions
	 */
	@OneToMany(targetEntity=Criterion.class,mappedBy="conference",cascade=CascadeType.ALL)
	public List<Criterion> getCriterions() {
		return criterions;
	}

	@OneToMany(targetEntity=Criterion.class,mappedBy="conference",cascade=CascadeType.ALL)
	public void setCriterions(List<Criterion> criterions) {
		this.criterions = criterions;
	}

}
