package com.ext.eai.trace;

import com.eactive.eai.common.message.EAIMessage;
import com.eactive.eai.common.property.PropManager;
import com.eactive.eai.common.util.Logger;

@Deprecated
public class TranManagerWrapper {
	protected static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
	public static String start1(EAIMessage eaiMsg){
		String traceGeneratorYn = PropManager.getInstance().getProperty("TRACE", "trace.generator.yn", "Y");
		if (!"Y".equals(traceGeneratorYn)){
			return null;
		}
		String json = getJSONString(eaiMsg);
		logger.debug("TranManagerWrapper] start1 GUID["+eaiMsg.getMapper().getGuid(eaiMsg.getStandardMessage()) 
				+ "."+eaiMsg.getMapper().getGuidSeq(eaiMsg.getStandardMessage()) + "]" + json);
		return json;
	}
	public static String end1(EAIMessage eaiMsg){
		String traceGeneratorYn = PropManager.getInstance().getProperty("TRACE", "trace.generator.yn", "Y");
		if (!"Y".equals(traceGeneratorYn)){
			return null;
		}
		String json = getJSONString(eaiMsg);
		logger.debug("TranManagerWrapper] end1 GUID["+eaiMsg.getMapper().getGuid(eaiMsg.getStandardMessage()) 
				+ "."+eaiMsg.getMapper().getGuidSeq(eaiMsg.getStandardMessage()) + "]" + json);
		return json;
	}
	public static String start2(EAIMessage eaiMsg){
		String traceGeneratorYn = PropManager.getInstance().getProperty("TRACE", "trace.generator.yn", "Y");
		if (!"Y".equals(traceGeneratorYn)){
			return null;
		}
		String json = getJSONString(eaiMsg);
		logger.debug("TranManagerWrapper] start2 GUID["+eaiMsg.getMapper().getGuid(eaiMsg.getStandardMessage()) 
				+ "."+eaiMsg.getMapper().getGuidSeq(eaiMsg.getStandardMessage()) + "]" + json);		
		return json;
	}
	public static String end2(EAIMessage eaiMsg){
		String traceGeneratorYn = PropManager.getInstance().getProperty("TRACE", "trace.generator.yn", "Y");
		if (!"Y".equals(traceGeneratorYn)){
			return null;
		}
		String json = getJSONString(eaiMsg);		
		logger.debug("TranManagerWrapper] end2   GUID["+eaiMsg.getMapper().getGuid(eaiMsg.getStandardMessage()) 
				+ "."+eaiMsg.getMapper().getGuidSeq(eaiMsg.getStandardMessage()) + "]" + json);
		return json;
	}
	private static String getJSONString(EAIMessage eaiMsg){
//		ExtMessage ext = eaiMsg.getExtMsg();
//		STDMessage std = (STDMessage)ext.getStdMessage();
//		Object message = ext.getBizData()[0];
//		String msg ="";
//		if (message instanceof String){
//			msg =(String)message;
//		}else if (message instanceof byte[]){
//			try {
//				msg = new String((byte[])message,"utf-8");
//			} catch (UnsupportedEncodingException e) {
//				e.printStackTrace();
//			}
//		}
//		return msg;
		try {
			return eaiMsg.getStandardMessage().getBizData();
		} catch (Exception e) {
			logger.error(e);
			return null;
		}
	}
}
