package com.eactive.eai.message.service;

import java.util.Properties;

import com.eactive.eai.common.message.EAIMessage;
import com.eactive.eai.common.server.EAIServerManager;
import com.eactive.eai.common.util.UUIDGenerator;
import com.eactive.eai.inbound.processor.ProcessVO;
import com.eactive.eai.message.StandardMessage;
import com.eactive.eai.message.manager.StandardMessageManager;
import com.ext.eai.common.stdmessage.STDMessageKeys;

public class DefaultStandardMessageCoordinator implements StandardMessageCoordinator {

	@Override
	public void coordinateAfterParsing(StandardMessage standardMessage, Object paramObject, Properties prop) {
	}

	@Override
	public void coordinateAfterCreateMessageByRule(StandardMessage standardMessage, Object paramObject, Properties prop) {
		// guid 설정
		EAIServerManager eaiServerManager = EAIServerManager.getInstance();
		StandardMessageManager standardManager = StandardMessageManager.getInstance();
		InterfaceMapper mapper = standardManager.getMapper();
		mapper.setGuid(standardMessage, UUIDGenerator.getGUID(eaiServerManager.getSystemType()));
	}

	@Override
	public void coordinateBeforeStandardMessageSend(StandardMessage standardMessage, String msgType, String charset) {

	}

	@Override
	public void coordinateInReturnObject(StandardMessage standardMessage) {
	}

	@Override
	public void coordinateBeforeInboundErrorResponse(StandardMessage standardMessage) {
	}

	@Override
	public boolean coordinateSetStandardMessageError(StandardMessage standardMessage, InterfaceMapper mapper,
			String errCode, String errMsg) {
		if (errCode != null) {
			mapper.setErrorCode(standardMessage, errCode);
		}
		if (errMsg != null) {
			mapper.setErrorMsg(standardMessage, errMsg);
		}		
		return true;
	}

	@Override
	public void coordinateAfterRestored(StandardMessage restoredMessage, StandardMessage responseMessage) {
		StandardMessageManager standardManager = StandardMessageManager.getInstance();
		InterfaceMapper mapper = standardManager.getMapper();
		mapper.setSendRecvDivision(restoredMessage, STDMessageKeys.SEND_RECV_CD_RECV);   
	}

	@Override
	public boolean coordinateIsWaitCheckForSync(StandardMessage responseMessage) {
		return false;
	}

	@Override
	public int coordinateForTimeoutCodeToValue(EAIMessage eaiMessage) {
		return eaiMessage.getCurrentSvcMsg().getTmoVl();
	}

	@Override
	public boolean coordinateValidation(StandardMessage standardMessage, ProcessVO vo) {
		return true;
	}

	@Override
	public void coordinateAfterRecvNonStdSyncResponse(StandardMessage responseMessage) {
		
	}

	@Override
	public void coordinateBeforeResponse(StandardMessage standardMessage, ProcessVO processVO, Properties prop, String charset) {
	}
}
