package com.palmnest.model;

import java.io.Serializable;

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

/**
 * This class is used to represent available roles in the database.
 *
 * @author <a href="mailto:chasel.java@gmail.com">Chasel Li</a>
 */
@Entity
@Table(name = "tr_app_role_function")
public class RoleFunction implements Serializable {

	private static final long serialVersionUID = 8145253920872743416L;

	private Integer     id;
	private Role        role;
	private AppFunction function;
	private String      operateStr;

	public RoleFunction() {

	}

	public RoleFunction(Role role, AppFunction function) {
		super();
		this.role = role;
		this.function = function;
		this.operateStr = "1,2,3,";
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "ID", unique = true, nullable = false)
	public Integer getId() {
		return id;
	}

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

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, optional = false)
	@JoinColumn(name = "ROLEID")
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "FUNCTION_ID")
	public AppFunction getFunction() {
		return function;
	}

	public void setFunction(AppFunction function) {
		this.function = function;
	}

	@Column(name = "OPERATE_STR")
	public String getOperateStr() {
		return operateStr;
	}

	public void setOperateStr(String operateStr) {
		this.operateStr = operateStr;
	}

}
