package servlet;

import java.io.IOException;
import java.util.List;

import DAO.*;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import metier.Session;
import metier.Utilisateur;

@WebServlet(name = "session", urlPatterns = {"/SessionInfo"})
public class SessionInfo extends HttpServlet {
    SessionDAO sessionDAO = new SessionDAO();
    UtilisateurDAO uDAO = new UtilisateurDAO();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/Session.html").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // Créer une nouvelle session
        String theme = req.getParameter("theme");
        String codePin = req.getParameter("codePIN");
        Session s = new Session();
        s.setCodePIN(Integer.parseInt(codePin));
        s.setTheme(theme);
        sessionDAO.create(s);

        resp.getWriter().println("<h1>Session creee avec  id: " +
                s.getId() + "</h1>");
        resp.getWriter().println("<h1>Session creee avec code PIN: " +
                s.getCodePIN() + "</h1>");
    }
}
