package org.yacos.core.article;


import java.io.Serializable;

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

import org.yacos.core.users.User;

/**
 * PreferencePK
 * Primary key for preferences
 * 
 * @author christiancorsano
 *
 */
public class PreferencePK implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * Public key, following these recomandations : http://www.jpox.org/docs/1_2/primary_key.html
	 */
	
	@ManyToOne(targetEntity=User.class)
	@JoinColumn(name="pcmember_id",nullable=false)
	public User pcMember;
	/**
	 * Public key, following these recomandations : http://www.jpox.org/docs/1_2/primary_key.html
	 */
	
	@ManyToOne(targetEntity=Article.class)
	@JoinColumn(name="article_id",nullable=false)
	public Article article;
	
	@Override
	public boolean equals(Object obj) {
		if (! (obj instanceof PreferencePK) ) {
			return false;
		}
		PreferencePK other = (PreferencePK) obj;
		return this.pcMember.getLogin().equals(other.pcMember.getLogin()) &&
				this.article.getId() == other.article.getId();
	}
	
	@Override
	public int hashCode() {
		return this.pcMember.getLogin().hashCode() ^ this.article.getId();
	}
}
