package ru.javastudy.spring.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import ru.javastudy.spring.cats.Cat;
import ru.javastudy.spring.cats.CatsFactory;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


@Controller
public class PDFController {


    @Inject
    private CatsFactory catsFactory;
    public CatsFactory getFlowModel() {
        return catsFactory;
    }

    public void setFlowModel(CatsFactory flowModel) {
        this.catsFactory = catsFactory;
    }

    @RequestMapping(value = "/downloadPDF", method = RequestMethod.GET)
    public ModelAndView downloadPDF(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
        List<Cat> cats = CatsFactory.createCats();
        model.put("cats", cats);
        return new ModelAndView("pdfView", "cats", cats);
    }

    @RequestMapping(value = "/pdfFromTable", method = RequestMethod.GET)
    public ModelAndView flowPDF() {
        List cats =  catsFactory.getCats();
        return new ModelAndView("pdfView", "cats", cats);
    }

}
