package siprp.higiene.relatorio.print;

import java.util.Vector;

import org.jdom.Element;

public class AreaToPrint
	implements PrintableInterface, Comparable
{
	protected String designacao;
	protected Vector<PostoToPrint> postos;
	protected Integer ordem;
	protected boolean temGenerico;
	
	public AreaToPrint( String designacao, Vector<PostoToPrint> postos, Integer ordem, boolean temGenerico )
	{
		super();
		this.designacao = designacao;
		this.postos = postos;
		this.ordem = ordem;
		this.temGenerico = temGenerico;
	}

	@Override
	public Element toJdomElement() throws Exception
	{
		Element areaElement = new Element( "area" );
		Element designacaoElement = new Element( "designacao" );
		designacaoElement.setText( designacao );
		areaElement.addContent( designacaoElement );
		for( PostoToPrint posto : postos )
		{
			areaElement.addContent( posto.toJdomElement() );
		}
		return areaElement;
	}

	@Override
	public int compareTo(Object o)
	{
		if( o instanceof AreaToPrint )
		{
			if( temGenerico && !( ( AreaToPrint ) o ).temGenerico )
			{
				return -1;
			}
			else if( !temGenerico && ( ( AreaToPrint ) o ).temGenerico )
			{
				return 1;
			} 
			if( ordem != null )
			{
				return ( ( ( AreaToPrint ) o ).ordem == null ) ? -1 : ordem.compareTo( ( ( AreaToPrint ) o ).ordem );
			}
		}
		return 0;
	}

}
