package cokr.xit.fims;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import cokr.xit.foundation.data.DataObject;
import cokr.xit.foundation.web.AbstractController;
import cokr.xit.foundation.web.RequestHandlerReader;

@Controller
public class MainController extends AbstractController {
	@Autowired
	private RequestMappingHandlerMapping requestHandlers;

	@GetMapping(name="로그인", value="/login.do")
	public String loginPage() {
		return "login";
	}

	@GetMapping(name="홈", value={"/", "/index.do"})
	public ModelAndView mainPage() {
		return new ModelAndView("index");
	}

	@RequestMapping(name="기능 URL 선택", value="/urls.do")
	public ModelAndView getURLs(boolean multiple) {
		List<DataObject> urls = new RequestHandlerReader().read(requestHandlers);
		return new ModelAndView("select-url")
			.addObject("multiple", multiple)
			.addObject("urls", toJson(urls));
	}
}