package sklep.basket;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import jakarta.servlet.http.HttpSession;
import jakarta.servlet.http.HttpSessionEvent;
import jakarta.servlet.http.HttpSessionListener;

@Configuration
public class BasketConfig {
	
	{ System.out.println("BasketConfig jest tworzony"); }
	
	@Bean
	HttpSessionListener createListener() {
		return new HttpSessionListener() {
			@Override
			public void sessionCreated(HttpSessionEvent se) {
				HttpSession session = se.getSession();
				// session.setMaxInactiveInterval(60);
				session.setAttribute("basket", new Basket());
				// System.out.println("Początek sesji " + session.getId());
			}

			@Override
			public void sessionDestroyed(HttpSessionEvent se) {
				// System.out.println("Koniec sesji " + se.getSession().getId());
			}
		};
	}

}
