package cokr.xit.fims.sprt.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.base.web.ApplicationController;
import cokr.xit.fims.sprt.service.bean.MediaBean;
import cokr.xit.foundation.data.DataObject;

@Controller
@RequestMapping(name="동영상 재생", value="/sprt/sprt03")
public class Sprt03Controller extends ApplicationController {
	@Resource(name="fileBean")
	private FileBean fileBean;
	@Resource(name="mediaBean")
	private MediaBean mediaBean;

	/** 동영상 재생 메인화면을 연다.
	 * @return fims/sprt/sprt03010-main
	 */
	@RequestMapping(name="동영상 재생 메인", value="/010/main.do")
	public ModelAndView videoMain(String openerPageName, String crdnId) {
		ModelAndView mav = new ModelAndView("fims/sprt/sprt03010-main")
			.addObject("openerPageName", openerPageName);

		if(!isEmpty(crdnId)) {
			mav.addObject("crdnId", crdnId);
			DataObject file = mediaBean.getVideoInfo(crdnId);
			if(!file.isEmpty()) {
				mav.addObject("fileInfo", toJson(file));
			}
		}

		return mav;
	}

	/** 사진 편집 메인화면을 연다.
	 * @return fims/sprt/sprt03020-main
	 */
	@RequestMapping(name="사진 편집 메인", value="/020/main.do")
	public ModelAndView editPhotoMain(String openerPageName, String fileId) {
		ModelAndView mav = new ModelAndView("fims/sprt/sprt03020-main")
			.addObject("openerPageName", openerPageName);

		if(!isEmpty(fileId)) {
			mav.addObject("fileId", fileId);

			FileQuery fileQuery = new FileQuery()
				.setFileIDs(fileId);
			List<DataObject> fileList = fileBean.getFileList(fileQuery);
			if(!isEmpty(fileList)) {
				DataObject file = fileList.get(0);
				mav.addObject("fileInfo", toJson(file));
			}
		}

		return mav;
	}
}