package com.example.backend.core.api;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;

import com.example.backend.core.session.SessionCart;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

@ControllerAdvice
public class GlobalController {
    private final SessionCart cart;

    public GlobalController(SessionCart cart) {
        this.cart = cart;
    }

    @ModelAttribute("servletPath")
    String getRequestServletPath(HttpServletRequest request) {
        return request.getServletPath();
    }

    @ModelAttribute("totalCart")
    int getTotalCart(HttpSession session) {
        return cart.getCount();
    }
}
