package com.eactive.eai.rms.onl.common.sql;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

@Service
public class BatInterfaceSqlService extends ExtractSqlService {
	
public String batInterfaceSql(String interfaceId) throws Exception {
		
		StringBuilder sqlBuilder = new StringBuilder();
		
		/** Interface **/
		List<Map<String, Object>> ea04_queryResult = select("TSEAIEA04", "INTFID", interfaceId);
		sqlBuilder.append(makeSql("TSEAIEA04", "INTFID", interfaceId, ea04_queryResult));
		
		/** FF Adapter **/
		List<Map<String, Object>> ea03_queryResult = select("TSEAIEA03", "INTFID", interfaceId);
		sqlBuilder.append(makeSql("TSEAIEA03", "INTFID", interfaceId, ea03_queryResult));
		
		/** DD Adapter **/
		List<Map<String, Object>> ea05_queryResult = select("TSEAIEA05", "INTFID", interfaceId);
		sqlBuilder.append(makeSql("TSEAIEA05", "INTFID", interfaceId, ea05_queryResult));
		
		/** AdapterDetail **/
//		String[] keysForEA02 = ArrayUtils.addAll(extractKeys(ea03_queryResult, "ADPTRCD"), extractKeys(ea05_queryResult, "ADPTRCD"));
//		List<Map<String, Object>> ea02_queryResult = select("TSEAIEA02", "ADPTRCD", keysForEA02);
//		sqlBuilder.append(makeSql("TSEAIEA02", "ADPTRCD", keysForEA02, ea02_queryResult));
		
		/** Scheduler **/
		List<Map<String, Object>> es07_queryResult = select("TSEAIES07", "INTFID", interfaceId);
		sqlBuilder.append(makeSql("TSEAIES07", "INTFID", interfaceId, es07_queryResult));
		
		/** SchedulerDetail **/
		String[] keysForES09 = extractKeys(es07_queryResult, "BJOBMSGSCHEID");
		List<Map<String, Object>> es09_queryResult = select("TSEAIES09", "BJOBMSGSCHEID", keysForES09);
		sqlBuilder.append(makeSql("TSEAIES09", "BJOBMSGSCHEID", keysForES09, es09_queryResult));
		
		return sqlBuilder.toString();
	}

}
