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.api.MPlusApi;
import com.dbs.mplus.service.api.MPlusApiCallService;
/**
 * 동의서 세트
 * @author siyoung.ahn
 *
 */
@Controller
@RequestMapping("/mobile/consent/set")
public class ConsentSetController extends AbstractController{
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private MPlusApiCallService apiCallService; 	
	
	/**
	 * 동의서 세트 리스트 조회
	 * @param request
	 * @param response
	 * @param reqMap
	 */
	@RequestMapping(value = "/getConsentSetList.json", method = RequestMethod.POST)
	public Map<String, Object> getConsentSetList(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("userNo", reqMap.get("pId"));
			return ResponseUtil.wrapResultMap( this.apiCallService.execute(MPlusApi.CONSENT_SET_GETCONSENTSETLIST, 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 = "/setUserFormSetList.json", method = RequestMethod.POST)
	public Map<String, Object> setUserFormSetList(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( this.apiCallService.execute(MPlusApi.CONSENT_SET_SETUSERFORMSETLIST, 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 = "/delUserFormSetList.json", method = RequestMethod.POST)
	public Map<String, Object> delUserFormSetList(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( this.apiCallService.execute(MPlusApi.CONSENT_SET_DELUSERFORMSETLIST, reqMap) ); 
		}
		catch(ApiCallException ex) { 
			if(this.logger.isDebugEnabled()) {
				this.logger.debug("예외발생", ex); 
			}
			
			throw new MobileControllerException("mplus.error.if.system", "시스템 호출 오류가 발생했습니다 (IF)");
		}
	}
}