package info.bukova.isspst.data;

import info.bukova.isspst.Constants;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Embedded;
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;

import org.hibernate.search.annotations.Analyze;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Indexed;

@Entity
@Table(name = "ORDER_ITEM")
@Indexed
public class OrderItem
{

	@Id
	@Column(name = "ID")
	@GeneratedValue
	private int id;

	@Column(name = "CODE")
	private String code;

	@Column(name = "NAME")
	@Field(index = Index.YES, analyze = Analyze.YES)
	private String name;

	@Column(name = "TEXTITEM")
	@Field(index = Index.YES, analyze = Analyze.YES)
	private String textItem;

	@Column(name = "QUANTITY", precision = 15, scale = 4)
	private BigDecimal quantity;

	@Embedded
	private MUnitEmb munit;

	@Column(name = "UNITPRICE", precision = 15, scale = 4)
	private BigDecimal unitPrice;

	@Column(name = "TOTAL", precision = 15, scale = 4)
	private BigDecimal total;

	@Column(name = "DESCRIPTION", length = Constants.LEN_DESCRIPTION)
	@Field(index = Index.YES, analyze = Analyze.YES)
	private String description;

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "REQUIREMENT_ITEM_ID")
	private RequirementItem reqItem;

	@ManyToOne
	@JoinColumn(name = "ORDER_ID")
	private Order order;

	public OrderItem()
	{
		super();
	}

	public OrderItem(RequirementItem reqItem)
	{
		super();
		this.reqItem = reqItem;
		this.code = reqItem.getCode();
		this.name = reqItem.getName();
		this.textItem = reqItem.getTextItem();
		this.quantity = reqItem.getQuantity();
		this.unitPrice = reqItem.getUnitPrice();
		this.munit = reqItem.getMunit();
		this.total = reqItem.getTotal();
		this.description = reqItem.getDescription();
	}

	public int getId()
	{
		return id;
	}

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

	public String getCode()
	{
		return code;
	}

	public void setCode(String code)
	{
		this.code = code;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getTextItem()
	{
		return textItem;
	}

	public void setTextItem(String textItem)
	{
		this.textItem = textItem;
	}

	public BigDecimal getQuantity()
	{
		return quantity;
	}

	public void setQuantity(BigDecimal quantity)
	{
		this.quantity = quantity;
	}

	public MUnitEmb getMunit()
	{
		return munit;
	}

	public void setMunit(MUnitEmb munit)
	{
		this.munit = munit;
	}

	public BigDecimal getUnitPrice()
	{
		return unitPrice;
	}

	public void setUnitPrice(BigDecimal unitPrice)
	{
		this.unitPrice = unitPrice;
	}

	public BigDecimal getTotal()
	{
		return total;
	}

	public void setTotal(BigDecimal total)
	{
		this.total = total;
	}

	public String getDescription()
	{
		return description;
	}

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

	public RequirementItem getReqItem()
	{
		return reqItem;
	}

	public void setReqItem(RequirementItem reqItem)
	{
		this.reqItem = reqItem;
	}

	public Order getOrder()
	{
		return order;
	}

	public void setOrder(Order order)
	{
		this.order = order;
	}

}
