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

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

import org.springframework.stereotype.Service;

@Service
public class AdapterSqlService extends ExtractSqlService {
	
	public String adapterSql(Map<String, Object> paramMap) throws Exception {
		
		StringBuilder sqlBuilder = new StringBuilder();
		
		String adapterGroupName = (String) paramMap.get("adapterGroupName");
		
		List<Map<String, Object>> ad01_queryResult = select("TSEAIAD01", "ADPTRBZWKGROUPNAME", adapterGroupName);
		sqlBuilder.append(makeSql("TSEAIAD01", "ADPTRBZWKGROUPNAME", adapterGroupName, ad01_queryResult));
		
		List<Map<String, Object>> ad02_queryResult = select("TSEAIAD02", "ADPTRBZWKGROUPNAME", adapterGroupName);
		sqlBuilder.append(makeSql("TSEAIAD02", "ADPTRBZWKGROUPNAME", adapterGroupName, ad02_queryResult));
		
		List<Map<String, Object>> fr04_queryResult = select("TSEAIFR04", "ADPTRBZWKGROUPNAME", adapterGroupName);
		sqlBuilder.append(makeSql("TSEAIFR04", "ADPTRBZWKGROUPNAME", adapterGroupName, fr04_queryResult));
		
		String[] keysForAD14 = extractKeys(ad02_queryResult, "ADPTRBZWKNAME");
		List<Map<String, Object>> ad14_queryResult = select("TSEAIAD14", "PRPTYGROUPNAME", keysForAD14);
		sqlBuilder.append(makeSql("TSEAIAD14", "PRPTYGROUPNAME", keysForAD14, ad14_queryResult));
		
		List<Map<String, Object>> ad15_queryResult = select("TSEAIAD15", "PRPTYGROUPNAME", keysForAD14);
		sqlBuilder.append(makeSql("TSEAIAD15", "PRPTYGROUPNAME", keysForAD14, ad15_queryResult));
		
		return sqlBuilder.toString();
	}

}
