package cokr.xit.fims.crdn.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.servlet.ModelAndView;

import cokr.xit.base.code.CommonCode;
import cokr.xit.base.web.ApplicationController;
import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.CrdnQuery;
import cokr.xit.fims.crdn.service.CrdnService;
import cokr.xit.fims.crdn.service.CrdnStngService;

/**표지정보확인 서비스 웹 컨트롤러.<br />
 * {웹 컨텍스트}/crdn/crdn03 로 접근할 수 있다.
 * @author leebj
 */
public class Crdn03Controller extends ApplicationController {

	public static final String CLASS_URL = "/crdn/crdn03";

	public class METHOD_URL {
		public static final String
		tagInformationUndefinedDataMain = "/010/main.do",
		getTagInformationUndefinedDataList = "/030/list.do",
		updateTagInfo = "/030/update.do"
		;
	}

	@Resource(name="crdnService")
	private CrdnService crdnService;

	@Resource(name="crdnStngService")
	private CrdnStngService crdnStngService;

	/** 표지정보 미확인 자료 메인화면을 연다.
	 * @return fims/crdn/crdn03010-main
	 */
	public ModelAndView tagInformationUndefinedDataMain() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("fims/crdn/crdn03010-main");
		mav.addObject("pageName","crdn03010-main");

		Map<String, List<CommonCode>> commonCodes = getCodesOf("FIM003", "FIM010");
		addCodes(commonCodes, mav, "FIM003", "FIM010");
		return mav;
	}

	/**표지정보미확인자료 목록을 조회한다.<br />
	 * {@link CrdnService#getCrackdownList(CrdnQuery)} 참고
	 * @param req 표지정보미확인자료 목록 조회 조건
	 * @return jsonView
	 */
	public ModelAndView getTagInformationUndefinedDataList(CrdnQuery query) {
		query.setGridType("tagInformationUndefinedData");
		setFetchSize(query);
		return setCollectionInfo(new ModelAndView("jsonView"), crdnService.getCrackdownList(query),"");
	}

	/**표지정보 미확인 자료를 수정한다.
	 * @param crdn 단속 대장 정보
	 * @return jsonView
	 * <pre><code> {
	 *     "saved": 수정되었으면 true, 그렇지 않으면 false
	 * }</code></pre>
	 */
	public ModelAndView updateTagInfo(Crdn crdn) {

		boolean saved = crdnService.updateTagInfo(crdn);
		return new ModelAndView("jsonView")
			.addObject("saved", saved);
	}

}
