package info.bukova.isspst.data;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "JOBMAPPING")
public class JobMapping {

	@Id
	@Column(name = "ID")
	@GeneratedValue
	private int id;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "MEMBER_ID")
	private Member member;
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "ROLE_ID")
	private Role role;
	
	public JobMapping() {
		
	}
	
	public JobMapping(Member member, Role role) {
		this.member = member;
		this.role = role;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}
	
	@Override
	public boolean equals(Object o) {
		if (o instanceof JobMapping 
				&& ((JobMapping)o).getMember().equals(this.getMember())
				&& ((JobMapping)o).getRole().equals(this.getRole())) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		return this.getMember() + " - " + this.getRole().getDescription();
	}

}
