package siprp.update.updates;

import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.Vector;

import javax.imageio.ImageIO;

import com.evolute.module.updater.AbstractUpdate;
import com.evolute.utils.db.Executer;
import com.evolute.utils.sql.Assignment;
import com.evolute.utils.sql.BlobUpdate;
import com.evolute.utils.sql.Field;

public class V12_0_To_V12_1 extends AbstractUpdate
{
	
	public V12_0_To_V12_1()
	{
		super(12.0,12.1,"A actualizar assinatura de B\u00e1rbara Gon\u00e7alves");
	}
	
	@Override
	public void doUpdate() throws Exception
	{
		Executer executer = getExecuter();
		
		Integer ids[] = new Integer[]{ 
				129,
				};
		String assinaturas[] = new String[]{ 
				"siprp/update/updates/V12_0_To_V12_1_Barbara_Goncalves.png"
				};

		for( int n = 0; n < ids.length; n++ )
		{
			Vector<Assignment> assignments = new Vector<Assignment>();
			if( assinaturas[ n ] != null )
			{
				Integer assinaturaID = null;
				BufferedImage assinaturaImage = ImageIO.read( getClass().getClassLoader().getResourceAsStream( 
						assinaturas[ n ] ) );
				ByteArrayOutputStream assinaturaBytesStream = new ByteArrayOutputStream();
				ImageIO.write( assinaturaImage, "PNG", assinaturaBytesStream );

				BlobUpdate blobUpdate = new BlobUpdate("image","image_data",assinaturaBytesStream.toByteArray(),new Field("id").isEqual( ids[ n ] ) );
				executer.executeQuery( blobUpdate );
				assignments.add( new Assignment( "assinatura", assinaturaID ) );
			}

		}
	}
	
}
