package com.k_int.ciim.ui.json;

import java.text.SimpleDateFormat;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.springframework.stereotype.Component;

import com.k_int.ciim.data.hdo.CIIMAttachmentHDO;
import com.k_int.ciim.ref.MediaRecordTypeEnum;
import com.sun.jersey.api.view.ImplicitProduces;

@XmlRootElement(name="attachment") 
@ImplicitProduces("application/json;qs=5")
@XmlAccessorType(XmlAccessType.FIELD)
@Component
public class AttachmentJSON
{	
	@XmlTransient
	public static final SimpleDateFormat DEFAULT_FORMAT = new SimpleDateFormat("dd/MM/yyyy '<I>'HH:mm'</I>'");
	
	private Long id;
	private String name;
	private String type;
	private String location;
	private String height = "---";
	private String width = "---";
	private String in_use = Boolean.FALSE.toString();
	private String creation_date;

	protected AttachmentJSON(){;}
	
	public AttachmentJSON(CIIMAttachmentHDO hdo)
	{
		if(hdo != null)
		{
			this.id = hdo.getId();
			this.name = hdo.getName();
			this.location = hdo.getLocation();
			this.type = hdo.getConfirmedMediaType().toString();
				
			if(hdo.getConfirmedMediaType() == MediaRecordTypeEnum.IMAGE)
			{
				if(hdo.getHeight() != null)
				{
					this.height = hdo.getHeight().toString();	
				}
				if(hdo.getWidth() != null)
				{
					this.width = hdo.getWidth().toString();
				}
			}
			
			this.creation_date = DEFAULT_FORMAT.format(hdo.getCreationDate());
		}
	}
		
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getHeight() {
		return height;
	}

	public void setHeight(String height) {
		this.height = height;
	}

	public String getWidth() {
		return width;
	}

	public void setWidth(String width) {
		this.width = width;
	}
	
	public String getInUse() {
		return in_use;
	}

	public void setInUse(String inUse) {
		in_use = inUse;
	}

	public String getCreationDate() {
		return creation_date;
	}

	public void setCreationDate(String creationDate) {
		creation_date = creationDate;
	}
}
