package br.dsc.upe.poli.mvc;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.dsc.upe.poli.basicas.Resposta;
import br.dsc.upe.poli.operacoes.GeradorGrafico;
import flexjson.JSONSerializer;

/**
 * Servlet implementation class Grafico
 */
public class Grafico extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Grafico() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		double entrada1 = Double.parseDouble(request.getParameter("entrada1"));
		double entrada2 = Double.parseDouble(request.getParameter("entrada2"));
		double entrada3 = Double.parseDouble(request.getParameter("entrada3"));
		double entrada4 = Double.parseDouble(request.getParameter("entrada4"));
		double entrada5 = Double.parseDouble(request.getParameter("entrada5"));
		double entrada6 = Double.parseDouble(request.getParameter("entrada6"));
		
		  double[][] data = new double[][]{{entrada1, entrada2, entrada3},{entrada4, entrada5, entrada6}};

		try {
			GeradorGrafico gerador = new GeradorGrafico("País","Taxa de Desemprego","País X Taxa de Desemprego");
			String caminho = gerador.geracaoGraficoBarras(data);
			Resposta resp = new Resposta("Grafico",caminho);
		      
		      JSONSerializer serializer = new JSONSerializer();
				//response.setCharacterEncoding("UTF-8");
				response.getWriter().write(serializer.serialize(resp));
			  
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		  
	      
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
