package com.k_int.aggr2.mimsy.data.hdo;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name="MIMSY_TITLE")
public class TitleHDO // implements java.io.Serializable
{
	private static final long serialVersionUID = 1L;
	private Long id;
	private String title;
	private String type;
	private Boolean prior;
	private AttributionHDO attribution;
	
	protected TitleHDO() 
	{
		super();
	}
	
	public TitleHDO(String title, String type, boolean prior, AttributionHDO attribution) 
	{
		this.title=title;
		this.type=type;
		this.attribution=attribution;	
		this.prior=prior;
	}
	
	@Id
	@Column(name="ID")
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId()
	{
		return id;
	}
	
	public void setId(Long id)
	{
		this.id = id;
	}
	
	@Column(name="TITLE")
	public String getTitle()
	{
		return title;
	}
	
	public void setTitle(String title) 
	{
		this.title = title;
	}
	
	@Column(name="TITLE_TYPE")
	public String getType()
	{
		return type;
	}
	
	public void setType(String type) 
	{
		this.type = type;
	}
	
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="MIMSY_ATTRIBUTION_FK")
	public AttributionHDO getAttribution()
	{
		return attribution;
	}
	
	public void setAttribution(AttributionHDO attribution)
	{
		this.attribution = attribution;
	}
	
	@Column(name="PRIOR")
	public Boolean getPrior()
	{
		return prior;
	}
	
	public void setPrior(Boolean prior)
	{
		this.prior = prior;
	}
	
	public int hashCode()
	{
		return toString().hashCode();
	}
	
	 public boolean equals(Object o)
	  {
		  boolean retval=false;
		  if(o instanceof TitleHDO)
		  {
			  retval = (o.toString()).equals(this.toString());
		  }
			  
		  return retval;  
	  }
	
	
	public String toString()
	{
		StringBuilder builder = new StringBuilder();
		if(title!=null)
			builder.append(title);
		
		if(type!=null)
			builder.append(type);
		
		
		builder.append(Boolean.toString(prior));
		
		if(attribution!=null)
			builder.append(attribution);
		
		return builder.toString();
		
		
	}

}
