package siprp.database.cayenne.objects;

import siprp.database.cayenne.objects.auto._HsArea;

public class HsArea extends _HsArea {

	private static final long serialVersionUID = 1L;

	@Override
	public String getDescription()
	{
		return parseFromUnicode( super.getDescription() );
	}
	
	@Override
	public void setDescription( String nome )
	{
		super.setDescription( parseToUnicode( nome ) );
	}
	
	@Override
	public void save() throws Exception
	{
		Empresas empresa = getToEmpresas();
		if( empresa != null )
		{
			Integer maxOrder = 0;
			for( HsArea area : empresa.getHsAreaArray() )
			{
				Integer currentOrder = area.getOrder();
				if( currentOrder != null )
				{
					maxOrder = Math.max( currentOrder, maxOrder );
				}
			}
			this.setOrder( maxOrder + 1 );
		}
		super.save();
	}
	
	@Override
	public String toString()
	{
		return getDescription();
	}
}
