package cokr.xit.fims.sprt.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.servlet.ModelAndView;

import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.FileService;
import cokr.xit.base.web.ApplicationController;
import cokr.xit.fims.sprt.service.Sprt03Service;
import cokr.xit.foundation.data.DataObject;

public class Sprt03Controller extends ApplicationController {

	@Resource(name="fileService")
	FileService fileService;

	@Resource(name="sprt03Service")
	Sprt03Service sprt03Service;

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

		mav.setViewName("fims/sprt/sprt03010-main");
		mav.addObject("openerPageName", openerPageName);

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

		return mav;
	}

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

		mav.setViewName("fims/sprt/sprt03020-main");
		mav.addObject("openerPageName", openerPageName);

		if(fileId != null && !fileId.equals("")) {
			mav.addObject("fileId", fileId);

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

		return mav;
	}
}
