package com.eactive.eai.message.test;


import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eactive.eai.message.StandardDataType;
import com.eactive.eai.message.StandardItem;
import com.eactive.eai.message.StandardMessage;
import com.eactive.eai.message.StandardMessageUtil;
import com.eactive.eai.message.StandardType;
import com.eactive.eai.message.mapper.DefaultMessageMapper;
import com.eactive.eai.message.mapper.MessageMapper;

public class VersionMappingTest {
	static Logger logger = LoggerFactory.getLogger(VersionMappingTest.class);
	
	public VersionMappingTest() {

	}
	
	public static StandardMessage generateMessageFromItemList() {
		// Test generator from List definition (with default values)
		logger.debug("\n>> ----------------------------------------------------------------------------------");
		logger.debug(">> Test generator from List definition ( with default values)");
		ArrayList<StandardItem> list = new ArrayList<StandardItem>();
		StandardItem group = null;
		StandardItem item = null;
		group = new StandardItem("Header", 1, StandardType.GROUP, 1, 0, 0, null);
		list.add(group);
		item = new StandardItem("StndCicsTrncd", 2, StandardType.FIELD, 1, 10, StandardDataType.STRING, "");
		list.add(item);
		item = new StandardItem("StndIntnlStndTelgmLen", 2, StandardType.FIELD, 1, 10, StandardDataType.LL_NUMBER, "0");
		list.add(item);
		item = new StandardItem("StndTranBaseYmd", 2, StandardType.FIELD, 1, 10, StandardDataType.STRING, "");
		list.add(item);

		StandardItem group1 = new StandardItem("Common", 1, StandardType.GROUP, 0, 0, null);
		list.add(group1);
		group = new StandardItem("TranInfo", 2, StandardType.GROUP, 0, 0, null);
		list.add(group);
		item = new StandardItem("StndCicsTrncd", 3, StandardType.FIELD, 3, StandardDataType.STRING, "KB0");
		list.add(item);
		item = new StandardItem("StndTelgmRecvTranCd", 3, StandardType.FIELD, 10, StandardDataType.STRING, "");
		list.add(item);
		item = new StandardItem("StndPrcssRtdTranCd", 3, StandardType.FIELD, 10, StandardDataType.STRING, "");
		list.add(item);
		
		group = new StandardItem("Array", 1, StandardType.GRID, 3, 0, null);
		list.add(group);
		item = new StandardItem("Item1", 2, StandardType.FIELD, 10, StandardDataType.STRING, "JI6H");
		list.add(item);
		item = new StandardItem("Group", 2, StandardType.GRID, 1, StandardDataType.STRING, null);
		list.add(item);
		item = new StandardItem("gitem1", 3, StandardType.FIELD, 10, StandardDataType.STRING, "726");
		list.add(item);
		item = new StandardItem("gitem2", 3, StandardType.FIELD, 10, StandardDataType.STRING, "20220905");
		list.add(item);
		
		item = new StandardItem("bizData", 1, StandardType.BIZDATA, 0, StandardDataType.STRING, null);
		list.add(item);
		
		StandardMessage message = null;;
		try {
			message = StandardMessageUtil.generate(list);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		
		logger.debug("@toJson\n" + message.toJson());
		
		MessageMapper mapper = new DefaultMessageMapper();
		String targetPath = "Header.StndCicsTrncd";
		String sourcePath = "Common.TranInfo.StndCicsTrncd";
		mapper.map(message, sourcePath, message, targetPath);	
		logger.debug("@toJson\n" + message.toJson());
		
		return message;
	}
	
	public static void main(String[] args) throws Exception {
		generateMessageFromItemList();		
	}

}
