package fonctions;

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

import retro.DBConnexion;
import retro.Member;
import retro.Moderator;

public class ModeratorDAO {

public void insert_moderator(String nom_moderator, String prenom_moderator, String libelle_office){
		

		Connection connection= DBConnexion.getConnection();
		PreparedStatement ps=null;
		
		try {	
		
		String query="insert into moderator(nom_moderator,prenom_moderator,libelle_office) values(?,?,?)";
		 ps=connection.prepareStatement(query);
		 ps.setString(1, nom_moderator);
		 ps.setString(2, prenom_moderator);
		 ps.setString(3, libelle_office);

		 ps.executeUpdate();
		 		 
		 
		} catch (Exception e) {
			System.err.println(e);
		}
	}


public static void main(String[] args) {
	ModeratorDAO obj_ReadValues=new ModeratorDAO();
	
	obj_ReadValues.get_values();
}



public List<Moderator> get_values(){

	Connection connection= DBConnexion.getConnection();
	
	PreparedStatement ps=null;
	ResultSet rs=null;
	 List<Moderator> list=new ArrayList<Moderator>();
	
	try {
		String querry="SELECT * FROM moderator";
		ps=connection.prepareStatement(querry);	

		rs=ps.executeQuery();		
		
		while(rs.next()){
			
			Moderator obj_Moderator=new Moderator();
			System.out.println(rs.getInt("id_moderator"));
			System.out.println(rs.getString("nom_moderator"));
			System.out.println(rs.getString("prenom_moderator"));
			System.out.println(rs.getString("libelle_office"));

			
			obj_Moderator.setId_moderator(rs.getInt("id_moderator"));
			obj_Moderator.setNom_moderator(rs.getString("nom_moderator"));
			obj_Moderator.setPrenom_moderator(rs.getString("prenom_moderator"));
			obj_Moderator.setLibelle_office(rs.getString("libelle_office"));

			list.add(obj_Moderator);				
		}						
	} catch (Exception e) {
			System.out.println(e);
	}
	return list;
}

public List<Moderator> moderatorConnexion(String pseudo_admin, String mdp_admin){

	Connection connection= DBConnexion.getConnection();

	PreparedStatement ps=null;
	ResultSet rs=null;
	 List<Moderator> list=new ArrayList<Moderator>();

	try {
		String querry="SELECT * FROM moderator WHERE pseudo_moderator = ? AND mdp_moderator = ?";
		ps=connection.prepareStatement(querry);
		 ps.setString(1, pseudo_admin);
		 ps.setString(2, mdp_admin);

		rs=ps.executeQuery();

		while(rs.next()){

			Moderator obj_Moderator=new Moderator();
			System.out.println(rs.getInt("id_moderator"));
			System.out.println(rs.getString("nom_moderator"));
			System.out.println(rs.getString("prenom_moderator"));
			System.out.println(rs.getString("pseudo_moderator"));
			System.out.println(rs.getString("mdp_moderator"));
			System.out.println(rs.getString("libelle_office"));


			obj_Moderator.setId_moderator(rs.getInt("id_moderator"));
			obj_Moderator.setNom_moderator(rs.getString("nom_moderator"));
			obj_Moderator.setPrenom_moderator(rs.getString("prenom_moderator"));
			obj_Moderator.setPseudo_moderator(rs.getString("pseudo_moderator"));
			obj_Moderator.setMdp_moderator(rs.getString("mdp_moderator"));
			obj_Moderator.setLibelle_office(rs.getString("libelle_office"));

			list.add(obj_Moderator);
		}
	} catch (Exception e) {
			System.out.println(e);
	}
	return list;
}

}
