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.CIIMMediaDataHDO;
import com.sun.jersey.api.view.ImplicitProduces;

@XmlRootElement(name="media") 
@ImplicitProduces("application/json;qs=5")
@XmlAccessorType(XmlAccessType.FIELD)
@Component
public class MediaJSON
{
	@XmlTransient
	public static final SimpleDateFormat DEFAULT_FORMAT = new SimpleDateFormat("dd/MM/yyyy '<I>'HH:mm'</I>'");
	
	private Long id;
	private AttachmentJSON attachment;
	private String format_name;
	private String caption;
	private String credit_line;
	private String creation_date;
	private String last_updated;
	
	protected MediaJSON(){;}
	
	public MediaJSON(CIIMMediaDataHDO hdo)
	{
		if(hdo != null)
		{
			this.id = hdo.getId();
			this.attachment = new AttachmentJSON(hdo.getAttachment());
			
			if(hdo.getFormatName() != null)
			{
				this.format_name = hdo.getFormatName();
			}
			else
			{
				this.format_name = "---";
			}
			
			this.caption = hdo.getCaption();
			this.credit_line = hdo.getCreditLine();
			this.creation_date = DEFAULT_FORMAT.format(hdo.getCreationDate());
			this.last_updated = DEFAULT_FORMAT.format(hdo.getLastUpdated());
		}
	}

	public Long getId() 
	{
		return id;
	}

	public void setId(Long id) 
	{
		this.id = id;
	}

	public AttachmentJSON getAttachment() 
	{
		return attachment;
	}

	public void setAttachment(AttachmentJSON attachment) 
	{
		this.attachment = attachment;
	}

	public String getFormatName() 
	{
		return format_name;
	}

	public void setFormatName(String formatName) 
	{
		format_name = formatName;
	}

	public String getCaption()
	{
		return caption;
	}

	public void setCaption(String caption) 
	{
		this.caption = caption;
	}

	public String getCreditLine() 
	{
		return credit_line;
	}

	public void setCreditLine(String creditLine) 
	{
		credit_line = creditLine;
	}

	public String getCreationDate() 
	{
		return creation_date;
	}

	public void setCreationDate(String creationDate)
	{
		creation_date = creationDate;
	}

	public String getLastUpdated()
	{
		return last_updated;
	}

	public void setLastUpdated(String lastUpdated)
	{
		last_updated = lastUpdated;
	}
}
