package com.eactive.eai.custom.adapter.handler;

import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

import com.eactive.eai.adapter.handler.TemplateAdapterErrorMsgHandler;
import com.eactive.eai.adapter.http.dynamic.HttpAdapterServiceKey;
import com.eactive.eai.common.message.EAIMessage;
import com.eactive.eai.common.message.EAIMessageKeys;
import com.eactive.eai.common.util.Logger;
import com.eactive.eai.custom.message.StandardMessageCoordinatorDJB;
import com.eactive.eai.message.StandardItem;
import com.eactive.eai.message.StandardMessage;
import com.eactive.eai.message.manager.StandardMessageManager;
import com.eactive.eai.message.service.InterfaceMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class NaverpayAdapterErrorMsgHandler extends TemplateAdapterErrorMsgHandler {

	private static final Logger logger = Logger.getLogger(Logger.LOGGER_ADAPTER);

	private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
	
	/**
	 * 표준 -> 비표준 거래
	 * 아웃바운드 어댑터에서 Exception이 발생했을 때, Outbound Process 응답 메시지 생성
	 */
	@Override
	public Object generateOutboundErrorResponseMessage(String outboundadapterGroupName,
			String outboundadapterName, Properties callProp, Object outboundRequestData, EAIMessage resEaiMsg)
			throws Exception {
		
		StandardMessage standardMessage = resEaiMsg.getStandardMessage();
		// msg_dvcd = EM (에러메시지)
        standardMessage.setData(StandardMessageCoordinatorDJB.MSG_DVCD, "NM");

        // 출력속성코드 = 1(팝업)
        standardMessage.setData(StandardMessageCoordinatorDJB.MSG_OUTP_ATRB_CD, "1");

        // MSG_LIST 1건 구성
        standardMessage.setData(StandardMessageCoordinatorDJB.MSG_LIST_ROWCNT, "0");
        StandardItem msgPart = standardMessage.findItem("MSG");
        msgPart.getChilds().remove("MSG_LIST");

        StandardMessageManager manager = StandardMessageManager.getInstance();
        InterfaceMapper mapper = manager.getMapper();
        
        // mapper 에러코드 설정
        mapper.setErrorCode(standardMessage, "");
        mapper.setErrorMsg(standardMessage, "처리오류");

        // 성공 처리 처럼 진행한다.
        resEaiMsg.setRspErrCd(EAIMessageKeys.EAI_SUCCESS_CODE, false);
		
		return null;

	}

}
