package incheon.sgp.sea.web;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import incheon.ags.cms.admin.service.CleaningAdminService;
import incheon.sgp.sea.service.SgpSeaService;
import incheon.sgp.sea.vo.SgpSeaFilterVO;
import incheon.sgp.sea.vo.SgpSeaVO;
import incheon.sgp.tdr.web.SgpTdrController;
import incheon.sgp.sea.vo.SgpSeaFcltyVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import incheon.sgp.tdr.vo.DronePoiVO;
import incheon.sgp.tdr.vo.SgpTdrVO;
import incheon.sgp.sea.vo.AddressVO;

@Controller
@RequestMapping("/sgp/sea")
@Slf4j
public class SgpSeaController {

	
    @Resource(name = "sgpSeaService")
    private SgpSeaService sgpSeaService;

    @GetMapping("/main.do")
    public String seaList(SgpSeaFilterVO filterVO, Model model) {
        List<SgpSeaVO> seaList = null;
        model.addAttribute("seaList", seaList);
        
        model.addAttribute("pageTitle", "스마트도시 e-시설물 알리미");
    	model.addAttribute("headerTitle", "스마트도시 e-시설물 알리미");
    	
        return "/sgp/sea/seaMapMain"; 
    }
    
    // Ajax 요청 처리용 JSON 응답
     @RequestMapping(value = "/seaSearchAjax.do", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
     @ResponseBody
     public List<SgpSeaVO> seaSearchAjax(@RequestBody SgpSeaFilterVO filterVO) {    	 
         return sgpSeaService.seaList(filterVO);
     }
     
     @RequestMapping(value = "/chartDataAjax.do", method = RequestMethod.POST)
     @ResponseBody
     public Map<String, Object> getChartData(@RequestBody SgpSeaFilterVO filter) throws Exception {
         return sgpSeaService.seaStats(filter);
     }
     
     @RequestMapping(value="/seaTypeListAjax.do", method=RequestMethod.GET)
     @ResponseBody
     public List<SgpSeaVO> getSeaTypeList() throws Exception {
         return sgpSeaService.seaTypeList();
     }

     @RequestMapping(value="/seaTypeDetailListAjax.do", method=RequestMethod.GET)
     @ResponseBody
     public List<SgpSeaVO> getSeaTypeDetailList(@RequestParam String parentCode) throws Exception {
         return sgpSeaService.seaTypeDetailList(parentCode);
     }
     
     @PostMapping(value = "/save.do", produces = "application/json; charset=UTF-8")
     @ResponseBody
     public Map<String, Object> saveFclty(@RequestBody SgpSeaFcltyVO vo) {
         Map<String, Object> result = new HashMap<>();       
         
         try {
        	 sgpSeaService.saveFclty(vo);
         } catch (Exception e) {
         }

         return result;
     }
     
     @PostMapping(value = "/delete.do", produces = "application/json; charset=UTF-8")
     @ResponseBody
     public Map<String, Object> deleteFclty(@RequestBody SgpSeaFcltyVO vo) {
         Map<String, Object> result = new HashMap<>();         
         
         try {
        	 sgpSeaService.deleteFclty(vo);
         } catch (Exception e) {
         }

         return result;
     }
     
     // Ajax 요청 처리용 JSON 응답
      @RequestMapping(value = "/getAddress.do", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
      @ResponseBody
      public List<AddressVO> getAddressAjax(@RequestBody SgpSeaFilterVO filterVO) { 
    	  List<AddressVO> addr = sgpSeaService.getAddressByPoi(filterVO);
          //log.info("AddressVO=" + addr.toString());
          //model.addAttribute("tdr", tdr);
          return addr;
      }
     
     
     

}

