package org.yacos.core.users;

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;

public class RolePK implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
	 */
	
	@ManyToOne(targetEntity=User.class,optional=false)
	@JoinColumn(name="user_id",nullable=false)
	public User user;
	/**
	 * Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
	 */
	
	@ManyToOne(targetEntity=Conference.class,optional=false)
	@JoinColumn(name="conference_id",nullable=false)
	public Conference conference;
	/**
	 * Public key, as described here : http://www.jpox.org/docs/1_2/primary_key.html
	 */
	public RoleType type;
	
	public RolePK() {
	}
	
	public RolePK(User user, RoleType type, Conference conference) {
		super();
		this.user = user;

		this.type = type;
		this.conference = conference;
	}

	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof RolePK)) {
			return false;
		}
		RolePK otherPK = (RolePK) obj;
		return type.equals(otherPK.type)&&
				user.equals(otherPK.user)&&
				conference == otherPK.conference;
	}
	
	@Override
	public int hashCode() {
		return type.hashCode() ^ user.hashCode() ^ conference.hashCode();
	}
	
}
