package com.renttracker.renttrackeriknsa.Controller;

import com.renttracker.renttrackeriknsa.Services.PaiementServices;
import com.renttracker.renttrackeriknsa.Services.UserBienRolesServices;
import com.renttracker.renttrackeriknsa.Services.UserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class FactureController {
    @Autowired
    private UserServices userServices;

    @Autowired
    private UserBienRolesServices userBienRolesServices;

    @Autowired
    private PaiementServices paiementServices;

    @RequestMapping("/facture")
    public String list(Model model) {

        if (userServices.hasRole().size() == 1) {
            userBienRolesServices.getBien(2);
            model.addAttribute("getRole", userBienRolesServices.getBien(2));
            model.addAttribute("factures", paiementServices.getAllDette(userServices.getCurrentUserId()));

        }

        model.addAttribute("getName", userServices.getCurrentUsername());
        return "views/facture/list";
    }
}
