package br.dsc.upe.poli.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import br.dsc.upe.poli.banco.ConexaoFactory;

import br.dsc.upe.poli.basicas.Perfil;

public class PerfilDAO {

	private Connection connection;

	public PerfilDAO() throws ClassNotFoundException, SQLException {
		this.connection = new ConexaoFactory().getConexao();
	}

	public void cadastrar(Perfil perfil) throws SQLException {
		PreparedStatement stmt;
		stmt = connection
				.prepareStatement("INSERT INTO perfil (login, meio_ambiente,educacao,impostos,habitacao, emprego, saude, globalizacao,violencia,economia) VALUES (?,?,?,?,?,?,?,?,?,?)");
		stmt.setString(1, perfil.getLogin());
		stmt.setString(2, perfil.getMeioAmbiente());
		stmt.setString(3, perfil.getEducacao());
		stmt.setString(4, perfil.getImpostos());
		stmt.setString(5, perfil.getHabitacao());
		stmt.setString(6, perfil.getEmprego());
		stmt.setString(7, perfil.getSaude());
		stmt.setString(8, perfil.getGlobalizacao());
		stmt.setString(9, perfil.getViolencia());
		stmt.setString(10, perfil.getEconomia());
		stmt.execute();
		stmt.close();
		
	}

	
	
	
	
	
	
	

	
	public ArrayList<String> buscarInteresses(String login) throws SQLException {

		PreparedStatement stmt = connection
				.prepareStatement("SELECT * FROM perfil WHERE login = ?");
		stmt.setString(1, login);
		ResultSet rs = stmt.executeQuery();
		ArrayList<String> interesses = new ArrayList<String>();
		while (rs.next()) {
			
			if(rs.getString("meio_ambiente").equals("true")  ){
				interesses.add("Meio Ambiente");
			} if(rs.getString("educacao").equals("true")){
				interesses.add("Educação");
			} if(rs.getString("impostos").equals("true")){
				interesses.add("Impostos");
			} if(rs.getString("habitacao").equals("true")){
				interesses.add("Habitação");
			} if(rs.getString("emprego").equals("true")){
				interesses.add("Emprego");
			} if(rs.getString("saude").equals("true")){
				interesses.add("Saúde");
			} if(rs.getString("globalizacao").equals("true")){
				interesses.add("Globalização");
			} if(rs.getString("violencia").equals("true")){
				interesses.add("Violência");
			}if(rs.getString("economia").equals("true")){
				interesses.add("Economia");
			}

		}
		stmt.close();
		rs.close();
		return interesses;

	}
	
	

		
}
