package info.bukova.isspst.data;

import info.bukova.isspst.Constants;

import java.math.BigDecimal;
import java.util.Date;

/**
 * Položka schválených požadavků na materiál nebo službu
 */
public class JoinedItem implements DataModel, FilterableRequirement
{
	// Konstruktoři

	protected void CopyItem(RequirementItem item)
	{
		this.item = item;

		this.id = item.getId();
		this.reqSubject = item.getReqSubject();
		this.requirement = item.getRequirement();
		this.code = item.getCode();
		this.name = item.getName();
		this.textItem = item.getTextItem();
		this.quantity = item.getQuantity();
		this.munit = item.getMunit();
		this.unitPrice = item.getUnitPrice();
		this.total = item.getTotal();
		this.description = item.getDescription();
	}

	// Default konstruktor kvůli volání newInstance()
	public JoinedItem()
	{
		super();
	}

	public JoinedItem(RequirementItem item)
	{
		super();

		this.CopyItem(item);
	}

	public JoinedItem(RequirementItem item, Workgroup workgroup, Workgroup centre, User owner)
	{
		super();

		this.CopyItem(item);

		this.workgroup = workgroup;
		this.centre = centre;
		this.ownedBy = owner;
	}

	// Kdyby se přistupovalo k datům přes další strukturu, byl by to problém pro
	// tisk, řazení a Bůh ví co ještě

	private RequirementItem item;

	public RequirementItem getItem()
	{
		return item;
	}

	public void setItem(RequirementItem item)
	{
		this.item = item;
	}


	// Členové RequirementItem

	private int id;
	private RequirementSubject reqSubject;
	private Requirement requirement;
	private String code;
	private String name;
	private String textItem;
	private BigDecimal quantity;
	private MUnitEmb munit;
	private BigDecimal unitPrice;
	private BigDecimal total;
	private String description;

	public int getId()
	{
		return id;
	}

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

	public RequirementSubject getReqSubject()
	{
		return reqSubject;
	}

	public void setReqSubject(RequirementSubject reqSubject)
	{
		this.reqSubject = reqSubject;
	}

	public Requirement getRequirement()
	{
		return requirement;
	}

	public void setRequirement(Requirement requirement)
	{
		this.requirement = requirement;
	}

	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;
	}

	// Hodnoty z Requirement
	private Workgroup workgroup;
	private Workgroup centre;
	private User ownedBy;

	public Workgroup getWorkgroup() {
		return workgroup;
	}

	public void setWorkgroup(Workgroup workgroup) {
		this.workgroup = workgroup;
	}

	public Workgroup getCentre() {
		return centre;
	}

	public void setCentre(Workgroup centre) {
		this.centre = centre;
	}

	public User getOwnedBy() {
		return ownedBy;
	}

	public void setOwnedBy(User owner) {
		this.ownedBy = owner;
	}

	protected Boolean itemMaterial;

	public boolean isItemMaterialReal()
	{
		return ((this.requirement != null) && (this.requirement.getKind() == Constants.REQ_TYPE_MATERIAL));
	}

	public Boolean getItemMaterial()
	{
		return this.itemMaterial;
	}

	public void setItemMaterial(Boolean value)
	{
		this.itemMaterial = value;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (obj != null)
		{
			if (obj instanceof JoinedItem)
			{
				JoinedItem item = (JoinedItem) obj;

				return (this.getId() == item.getId());
			}
		}

		return false;
	}

	// Zbytenčné metody nutné kvůli přetížení z předka DataModel - chybka v
	// návrhu no...

	@Override
	public void setCreated(Date created)
	{
		// TODO Auto-generated method stub
	}

	@Override
	public Date getCreated()
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setModified(Date modified)
	{
		// TODO Auto-generated method stub
	}

	@Override
	public Date getModified()
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isValid()
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void setValid(boolean valid)
	{
		// TODO Auto-generated method stub
	}
}
