package org.yacos.core.users;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.yacos.core.conferences.Conference;


/**
 * An role of a given type (author,chairman,PCmember or referee)
 * defined for a user and a conference
 * @author christiancorsano
 *
 */
@Entity
@IdClass(RolePK.class)
public class Role implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * User for which this role is defined
	 * Primary Key
	 */
	@Id
	@ManyToOne(targetEntity=User.class,optional=false)
	@JoinColumn(name="user_id",nullable=false)
	private User user;
	/**
	 * Conference for which this role is defined
	 * Primary Key
	 */
	@Id
	@ManyToOne(targetEntity=Conference.class,optional=false)
	@JoinColumn(name="conference_id",nullable=false)
	private Conference conference;
	/**
	 * The type of this role
	 */
	public enum RoleType {
		AUTHOR,CHAIRMAN,PCMEMBER,REFEREE
	}
	
	@Id
	@Enumerated(EnumType.ORDINAL)
	private RoleType type;
	
	public Role(RoleType type,User user, Conference conference) {
		
		setType(type);
		setUser(user);
		setConference(conference);
	}
	
	public Role(){
		
	}
	
	public User getUser() {
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}


	public Conference getConference() {
		return conference;
	}


	public void setConference(Conference conference) {
		this.conference = conference;
	}


	/**
	 * @return the type of this role
	 */
	public RoleType getType() {
		return type;
	}
	/**
	 * @param type the type of this role
	 */
	public void setType(RoleType type) {
		this.type = type;
	}
	
}

