package com.jasamedika.medifirst2000.controller;

import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.entities.Kecamatan;
import com.jasamedika.medifirst2000.service.KecamatanService;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

@RestController
@RequestMapping("/kecamatan")
public class KecamatanController extends LocaleController {
	
	@Autowired
	private KecamatanService kecamatanService;
	
	
	private static final Logger LOGGER = LoggerFactory
			.getLogger(KecamatanController.class);

	
	  @RequestMapping("/kecamatanReport")
	    public ModelAndView generateReportMateri(ModelAndView m,@RequestParam(value = "format", required = false) String format){
		  
	        Iterable<Kecamatan> data = kecamatanService.findAllKecamatan();
	        
	        m.addObject("dataSource", data);
	        m.addObject("tanggalReport", new Date());
	        m.addObject("title", "Report Kecamatan");
	        m.addObject("format", "pdf");
	        
	        if(format != null && !format.isEmpty()){
	            m.addObject("format", format);
	        }
	        
	        return m;
	}
	  
}
