/**
 * 
 */
package org.yacos.core.system;

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;
import org.yacos.core.users.Role.RoleType;

/**
 * Token for an invitation.
 * Gives the ability for a user to gain role for a conference at registration time.
 * Allow a chairman or a PC member to gives a PC Member or Referee role to a person not yet registered. 
 * @author christiancorsano
 *
 */
@Entity
@IdClass(InvitationTokenPK.class)
public class InvitationToken implements Serializable {
	private static final long serialVersionUID = -7383377207105284233L;

	@Id
	private String email;
	
	@Id
	@Enumerated(EnumType.ORDINAL)
	private RoleType	role;
	
	@Id
	@ManyToOne(targetEntity=Conference.class,optional=false)
	@JoinColumn(name="conference_id",nullable=false)
	private Conference	conference;
	
	
	public String getEmail(){
		return email;
	}
	
	public void setEmail(String email){
		this.email = email;
	}
	
	@Enumerated(EnumType.ORDINAL)
	public RoleType getRole(){
		return role;
	}
	
	@Enumerated(EnumType.ORDINAL)
	public void setRole(RoleType role){
		this.role = role;
	}

	@ManyToOne(targetEntity=Conference.class,optional=false)
	@JoinColumn(name="conference_id",nullable=false)
	public Conference getConference(){
		return conference;
	}

	@ManyToOne(targetEntity=Conference.class,optional=false)
	@JoinColumn(name="conference_id",nullable=false)
	public void setConference(Conference conf){
		this.conference = conf;
	}
	
	public InvitationTokenPK getId(){
		return new InvitationTokenPK(email,role,conference);
	}
}
