package de.jottyfan.camporganizer.module.confirmation.confirmation;

import java.time.LocalDate;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import de.jottyfan.camporganizer.module.confirmation.confirmation.impl.CampOverviewBean;

/**
 *
 * @author jotty
 *
 */
@Controller
public class ConfirmationController {

	@Autowired
	private HttpServletRequest request;

	@Autowired
	private IConfirmationService indexService;

	@GetMapping("/confirmation")
	public String getIndex(Model model) {
		String username = indexService.getCurrentUser(request);
		List<CampOverviewBean> campoverview = indexService.getCampOverview(request);
		CampOverviewBean campoverviewsummary = new CampOverviewBean(LocalDate.now(), "summary");
		for (CampOverviewBean bean : campoverview) {
			campoverviewsummary.setApproved(bean.getApproved() + campoverviewsummary.getApproved());
			campoverviewsummary.setRejected(bean.getRejected() + campoverviewsummary.getRejected());
			campoverviewsummary.setUntouched(bean.getUntouched() + campoverviewsummary.getUntouched());
		}
		model.addAttribute("currentUser", username);
		model.addAttribute("campoverview", campoverview);
		model.addAttribute("campoverviewsummary", campoverviewsummary);
		model.addAttribute("untouched", indexService.getUntouched(request));
		model.addAttribute("approved", indexService.getApproved(request));
		model.addAttribute("rejected", indexService.getRejected(request));
		return "confirmation/confirmation";
	}
}
