package info.bukova.isspst.data;

import info.bukova.isspst.Constants;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "REQUIREMENTTYPE")
public class RequirementType extends BaseData {
	
	@Column(name = "TYPE")
	private String type;
	@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
	private String description;
	@OneToMany(cascade = CascadeType.ALL, orphanRemoval=true)
	@LazyCollection(LazyCollectionOption.FALSE)
	@OrderBy("CENTRE, WORDER")
	private List<Workflow> workflow;
	@Column(name = "LIMIT_CENTRES")
	private Boolean limitCentres;
	@ManyToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinTable(name="REQUIREMENTTYPE_WORKGROUP", joinColumns={@JoinColumn(name="REQUIREMENTTYPE_ID")}, inverseJoinColumns={@JoinColumn(name="WORKGROUP_ID")})
	private List<Workgroup> offeredCentres;
	
	public RequirementType() {
		workflow = new ArrayList<Workflow>();
		offeredCentres = new ArrayList<Workgroup>();
	}
	
	public RequirementType(String type, String description) {
		this();
		this.type = type;
		this.description = description;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Workflow> getWorkflow() {
		return workflow;
	}

	public void setWorkflow(List<Workflow> workflow) {
		this.workflow = workflow;
	}
	
	public boolean equals(Object o) {
		if (o instanceof RequirementType && ((RequirementType)o).getType().equals(this.type)) {
			return true;
		}
		
		return false;
	}

	public Boolean getLimitCentres() {
		return limitCentres;
	}

	public void setLimitCentres(Boolean limitCentres) {
		this.limitCentres = limitCentres;
	}

	public List<Workgroup> getOfferedCentres() {
		return offeredCentres;
	}

	public void setOfferedCentres(List<Workgroup> offeredCentres) {
		this.offeredCentres = offeredCentres;
	}

}
