package com.k_int.ciim.json;

import java.util.List;

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.aggr2.mimsy.data.hdo.SchemaElementHDO;
import com.k_int.aggr2.mimsy.data.hdo.SchemaOptionValueHDO;
import com.sun.jersey.api.view.ImplicitProduces;

@XmlRootElement
@ImplicitProduces("application/json;qs=5")
@XmlAccessorType(XmlAccessType.FIELD)
@Component
public class SchemaElementJSON 
{
	private Long id;	
	private Integer minOccurs = 0;
	private Integer maxOccurs = 1;
	private Integer maxLength = Integer.MAX_VALUE;
	private String display_name;
	private String description;
	private String type;
	private List<String> value;
	
	protected SchemaElementJSON(){;}
		
	public Long getId() 
	{
		return id;
	}

	public void setId(Long id) 
	{
		this.id = id;
	}

	public Integer getMinOccurs() 
	{
		return minOccurs;
	}

	public void setMinOccurs(Integer minOccurs) 
	{
		this.minOccurs = minOccurs;
	}

	public Integer getMaxOccurs() 
	{
		return maxOccurs;
	}

	public void setMaxOccurs(Integer maxOccurs) 
	{
		this.maxOccurs = maxOccurs;
	}
	
	public Integer getMaxLength() 
	{
		return maxLength;
	}

	public void setMaxLength(Integer maxLength) 
	{
		this.maxLength = maxLength;
	}

	public String getDisplayName() 
	{
		return display_name;
	}

	public void setDisplayName(String displayName) 
	{
		display_name = displayName;
	}

	public String getDescription() 
	{
		return description;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public String getType() 
	{
		return type;
	}

	public void setType(String type) 
	{
		this.type = type;
	}
	
	public List<String> getValue() 
	{
		return value;
	}

	public void setValue(List<String> value) 
	{
		this.value = value;
	}
	
	public static SchemaElementJSON schemaElementHDOtoJSON(SchemaElementHDO hdo)
	{
		SchemaElementJSON json = new SchemaElementJSON();
	
		if(hdo != null)
		{
			json.setId(hdo.getId());
			json.setMinOccurs(hdo.getMinOccurs());
			json.setMaxOccurs(hdo.getMaxOccurs());
			json.setMaxLength(hdo.getMaxLength());
			json.setDescription(hdo.getDescription());
			json.setDisplayName(hdo.getDisplayName());
			json.setType(hdo.getSchemaElementType().toString());
		}
		return json;
	}
	
	public static SchemaElementJSON schemaElementHDOtoJSON(SchemaElementHDO hdo, SchemaOptionValueHDO value)
	{
		SchemaElementJSON json = new SchemaElementJSON();
	
		if(hdo != null)
		{
			json.setId(hdo.getId());
			json.setMinOccurs(hdo.getMinOccurs());
			json.setMaxOccurs(hdo.getMaxOccurs());
			json.setMaxLength(hdo.getMaxLength());
			json.setDescription(hdo.getDescription());
			json.setDisplayName(hdo.getDisplayName());
			json.setType(hdo.getSchemaElementType().toString());
			
			if(value != null && value.getValues() != null)
			{
				json.setValue(value.getValues());
			}
		}
		return json;
	}
}
