package com.aplana.timesheet.controller;

import com.aplana.timesheet.util.DateTimeUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * User: iziyangirov
 * Date: 13.08.14
 */
@Controller
public class BirthdaysController extends AbstractControllerForEmployee {

    private ModelAndView createMAV(Integer month){
        ModelAndView mav = new ModelAndView("birthdays");
        mav.addObject("currentMonth", month);
        mav.addObject("employeesForSelectedMonth",
                employeeService.getEmployeesWithBirthdayMonth(month));
        return mav;
    }

    @RequestMapping(value = "/birthdays")
    public ModelAndView showBirthdaysDefault() {
        Integer month = DateTimeUtil.getMonth(new Date()) + 1;
        return createMAV(month);
    }

    @RequestMapping(value = "/birthdays/{month}")
    public ModelAndView showBirthdays(
            @PathVariable("month") Integer month
    ) {
        return createMAV(month);
    }
}
