package org.yacos.core.system;

import java.io.Serializable;

import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.yacos.core.conferences.Conference;
import org.yacos.core.users.Role.RoleType;

/**
 * Primary key class for the {@link InvitationToken} entity
 * @author christiancorsano
 *
 */
public class InvitationTokenPK implements Serializable {
	private static final long serialVersionUID = 1L;
	
	/**
	 * PK attribute : email
	 */
	public String email;
	/**
	 * PK attribute : role
	 */
	public RoleType role;
	/**
	 * PK attribute : conference
	 */
	@ManyToOne(targetEntity=Conference.class,optional=false)
	@JoinColumn(name="conference_id",nullable=false)
	public Conference conference;
	
	public InvitationTokenPK(String email2, RoleType role2,
			Conference conference2) {
		this.email = email2;
		this.role = role2;
		this.conference = conference2;
	}
	
	public InvitationTokenPK() {
	}

	@Override
	public boolean equals(Object obj) {
		if(obj instanceof InvitationTokenPK){
			InvitationTokenPK objPK = (InvitationTokenPK) obj;
			return this.email.equals(objPK.email)
					&& this.role.equals(objPK.role)
					&& this.conference.getId().equals(objPK.conference.getId());
		} else {
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return this.email.hashCode() ^ this.role.hashCode() ^ conference.getId().hashCode();
	}
}
