package kr.co.i4way.sample.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import kr.co.i4way.common.CommandMap;
import kr.co.i4way.sample.model.TestListVo;
import kr.co.i4way.sample.service.SampleService;

@Controller
public class SampleController {

	@Autowired(required=true)
	private SampleService service;
	
	//화면이 열림과 동시에 데이터를 보여줘야 하는경우
	@RequestMapping("/welcome")
	public String welcome() throws Exception{
    	return "/welcome";
	}	
	
	@RequestMapping("/ws_sample")
	public String websocket_sample() throws Exception{
	   	return "/websocket/ws_sample";
	}	

	@RequestMapping(value="/wall/openWall")
    public ModelAndView openWall() throws Exception{
    	ModelAndView mv = new ModelAndView("/wall/index");
    	return mv;
    }
	
	@RequestMapping(value="/wall/w_call")
    public ModelAndView openWall_call() throws Exception{
    	ModelAndView mv = new ModelAndView("/wall/wall_call");
    	return mv;
    }
	
	@RequestMapping(value="/wall/w_picture")
    public ModelAndView openWall_picture() throws Exception{
    	ModelAndView mv = new ModelAndView("/wall/wall_picture");
    	return mv;
    }
	
	@RequestMapping(value="/wall/w_movie")
    public ModelAndView openWall_movie() throws Exception{
    	ModelAndView mv = new ModelAndView("/wall/wall_movie");
    	return mv;
    }
	
	//화면이 열림과 동시에 데이터를 보여줘야 하는경우
	@RequestMapping("/getDual")
	public ModelAndView getDual() throws Exception{
		ModelAndView mv = new ModelAndView("/welcome");
		mv.addObject("time", service.getDual());
    	return mv;
	}
	
	@RequestMapping("/getTestList")
	public @ResponseBody Map<String , Object> getTestList(@ModelAttribute("testlistvo") TestListVo testlistvo) throws Exception{
		Map<String, Object> rtnObject = new HashMap<String, Object>();
		rtnObject.put("list", service.getTestList(testlistvo));
		rtnObject.put("param", testlistvo);
    	return rtnObject;
	}	
}
