package com.k_int.ciim.ui.json;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.stereotype.Component;

import com.k_int.ciim.data.hdo.ReferenceHDO;
import com.sun.jersey.api.view.ImplicitProduces;

@XmlRootElement(name="ref_link") 
@ImplicitProduces("application/json;qs=5")
@XmlAccessorType(XmlAccessType.FIELD)
@Component
public class RefLinkJSON extends AbstractJSON implements Comparable<RefLinkJSON>
{
	private Long id;
	private String identifier = null;
	private String relationship = "";
	private String type = null;
	private Integer position = 0;
	private String start = null;
	private String end = null;
	private String text = "";
	
	public RefLinkJSON(ReferenceHDO hdo)
	{
		if(hdo != null)
		{
			this.id = hdo.getId();
			this.identifier = hdo.getReferencedIdentifier();
			this.relationship = hdo.getRelationship();
			this.type = hdo.getReferencedType().toString();
			
			if(hdo.getDescriptiveText() != null)
			{
				this.text = hdo.getDescriptiveText();
			}
			if(hdo.getPosition() != null)
			{
				this.position = hdo.getPosition();
			}
			if(hdo.getStart() != null)
			{
				this.start = DEFAULT_FORMAT.format(hdo.getStart());
			}
			if(hdo.getEnd() != null)
			{
				this.end = DEFAULT_FORMAT.format(hdo.getEnd());
			}
		}
	}

	public Long getId() 
	{
		return id;
	}

	public void setId(Long id)
	{
		this.id = id;
	}

	public String getIdentifier() 
	{
		return identifier;
	}

	public void setIdentifier(String identifier) 
	{
		this.identifier = identifier;
	}

	public String getRelationship()
	{
		return relationship;
	}

	public void setRelationship(String relationship) 
	{
		this.relationship = relationship;
	}

	public String getType() 
	{
		return type;
	}

	public void setType(String type)
	{
		this.type = type;
	}

	public Integer getPosition()
	{
		return position;
	}

	public void setPosition(Integer position) 
	{
		this.position = position;
	}

	public String getStart() 
	{
		return start;
	}

	public void setStart(String start)
	{
		this.start = start;
	}

	public String getEnd()
	{
		return end;
	}

	public void setEnd(String end)
	{
		this.end = end;
	}
	
	public String getText() 
	{
		return text;
	}

	public void setText(String text)
	{
		this.text = text;
	}
	
	/* Comparator method used for sorting */
	public int compareTo(RefLinkJSON o) 
	{
		if(this.position == null || o.position == null)
		{
			return 0;
		}
        return this.position - o.position;
    }	
}
