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

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

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 org.springframework.web.bind.annotation.PathVariable;

import de.jottyfan.camporganizer.module.camplist.CommonController;
import de.jottyfan.camporganizer.module.confirmation.confirmation.model.CampOverviewBean;

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

	@Autowired
	private ConfirmationService service;

	@GetMapping("/confirmation")
	public String getIndex(Model model) {
		List<CampOverviewBean> campoverview = service.getCampOverview(super.getCurrentUser());
		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());
			campoverviewsummary.setRevoked(bean.getRevoked() + campoverviewsummary.getRevoked());
		}
		model.addAttribute("campoverview", campoverview);
		model.addAttribute("campoverviewsummary", campoverviewsummary);
		model.addAttribute("untouched", service.getUntouched(super.getCurrentUser()));
		model.addAttribute("approved", service.getApproved(super.getCurrentUser()));
		model.addAttribute("rejected", service.getRejected(super.getCurrentUser()));
		model.addAttribute("revoked", service.getRevoked(super.getCurrentUser()));
		return "confirmation/confirmation";
	}


	@GetMapping("/registration/remove/{id}")
	public String revoke(@PathVariable("id") Integer id, final Model model) {
		service.removeBooking(id);
		return "redirect:/confirmation";
	}

}
