package com.dbs.mplus.controller.mobile;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dbs.mplus.exception.mobile.ApiCallException;
import com.dbs.mplus.exception.mobile.MobileControllerException;
import com.dbs.mplus.framework.exception.MPlusServiceException;
import com.dbs.mplus.framework.template.AbstractController;
import com.dbs.mplus.framework.util.ResponseUtil;
import com.dbs.mplus.service.mobile.consent.ConsentService;
/**
 * 동의서 저장
 * @author siyoung.ahn
 *
 */
@Controller
@RequestMapping("/mobile/consent/save")
public class ConsentSaveController extends AbstractController{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	//@Autowired
	//private MPlusApiCallService apiCallService;
	
	@Autowired
	private ConsentService consentService;
	
	/**
	 * 동의서 삭제
	 * @param request
	 * @param response
	 * @param reqMap
	 */
	@RequestMapping(value = "/saveDelete.json", method = RequestMethod.POST)
	public Map<String, Object> saveDelete(HttpServletRequest request, HttpServletResponse response,
			@RequestBody Map<String, Object> reqMap) throws MobileControllerException { 
		// 접근권한 및 파라미터 정리 
		try { 
			reqMap = super.isAccessableMenu(this.getClass(), request, reqMap); 
		}
		catch(MPlusServiceException ex) { 
			throw new MobileControllerException(ex.getCode(), ex.getMessage()); 
		} 
		
		// 실행 
		try { 
			reqMap.put("userId", reqMap.get("pId"));
			return ResponseUtil.wrapResultMap( consentService.saveDelete(reqMap)); 
			
		}
		catch(ApiCallException ex) { 
			if(this.logger.isDebugEnabled()) {
				this.logger.debug("예외발생", ex); 
			}
			
			throw new MobileControllerException("mplus.error.if.system", "시스템 호출 오류가 발생했습니다 (IF)");
		}
	}

	
	/**
	 * 동의서 임시 저장
	 * @param request
	 * @param response
	 * @param reqMap
	 */
/*	@RequestMapping(value = "/saveTempData.json", method = RequestMethod.POST)
	public Map<String, Object> saveTempData(HttpServletRequest request, HttpServletResponse response,
			@RequestBody Map<String, Object> reqMap) throws MobileControllerException { 
		// 접근권한 및 파라미터 정리 
		try { 
			reqMap = super.isAccessableMenu(this.getClass(), request, reqMap); 
		}
		catch(MPlusServiceException ex) { 
			throw new MobileControllerException(ex.getCode(), ex.getMessage()); 
		} 
		
		// 실행 
		try { 

			return ResponseUtil.wrapResultMap( consentService.saveTempData(request, reqMap) ); 
			
		}
		catch(ApiCallException ex) { 
			if(this.logger.isDebugEnabled()) {
				this.logger.debug("예외발생", ex); 
			}
			
			throw new MobileControllerException("mplus.error.if.system", "시스템 호출 오류가 발생했습니다 (IF)");
		}
	}
	*/
	/**
	 * 동의서 완료 저장
	 * @param request
	 * @param response
	 * @param reqMap
	 */
	/*@RequestMapping(value = "/saveComplete.json", method = RequestMethod.POST)
	public Map<String, Object> saveComplete(HttpServletRequest request, HttpServletResponse response,
			@RequestBody Map<String, Object> reqMap) throws MobileControllerException { 
		// 접근권한 및 파라미터 정리 
		try { 
			reqMap = super.isAccessableMenu(this.getClass(), request, reqMap); 
		}
		catch(MPlusServiceException ex) { 
			throw new MobileControllerException(ex.getCode(), ex.getMessage()); 
		} 
		
		// 실행 
		try { 

			return ResponseUtil.wrapResultMap( consentService.saveComplete(request, reqMap) ); 
			
		}
		catch(ApiCallException ex) { 
			if(this.logger.isDebugEnabled()) {
				this.logger.debug("예외발생", ex); 
			}
			
			throw new MobileControllerException("mplus.error.if.system", "시스템 호출 오류가 발생했습니다 (IF)");
		}
	}
	*/
	

}