package com.bb.service;

import java.math.BigInteger;
import java.net.SocketTimeoutException;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import io.netty.channel.ConnectTimeoutException;
import io.netty.handler.timeout.ReadTimeoutException;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.util.UriComponentsBuilder;

import com.bb.dao.CommonDao;
import com.bb.model.BanGameSearch;
import com.bb.model.CmnSearch;
import com.bb.model.GameVo;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class CommonServiceImpl implements CommonService {

	@Autowired
	private CommonDao commonDao;
	
	@Autowired
	WebClient webClient;
	
	@Override
	public List<HashMap<String, String>> getGameCategoryList() {
		// TODO Auto-generated method stub
		return commonDao.getGameCategoryList();
	}

	@Override
	public List<HashMap<String, Object>> getGameVendorList(CmnSearch search) {
		// TODO Auto-generated method stub
		return commonDao.getGameVendorList(search);
	}

	@Override
	public List<HashMap<String, Object>> getBanGameList(BanGameSearch search) {
		// TODO Auto-generated method stub
		return commonDao.getBanGameList(search);
	}

	@Override
	public int insertBanGameInfo(HashMap<String, Object> item) {
		// TODO Auto-generated method stub
		return commonDao.insertBanGameInfo(item);
	}

	@Override
	public int insertNexusGameInfo(HashMap<String, Object> item) {
		// TODO Auto-generated method stub
		return commonDao.insertNexusGameInfo(item);
	}

	@Override
	public HashMap getVendorApiInfo(CmnSearch search) {
		// TODO Auto-generated method stub
		return commonDao.getVendorApiInfo(search);
	}

	@Override
	public List<GameVo> getGrandGameList(String LOG_PREFIX, HashMap<String, Object> apiInfo) {
		List<GameVo> gameList = null;
		long vendorIdx = (long) apiInfo.get("vendorIdx");
		String vendorApiUrl = apiInfo.get("vendorApiUrl").toString();
		String vendorApiId = apiInfo.get("vendorApiId").toString();
		String vendorApiKey = apiInfo.get("vendorApiKey").toString();
		String vendorGameCode = apiInfo.get("vendorGameCode").toString();
		String vendorTitle = apiInfo.get("vendorTitle").toString();
		
		try {
			HttpHeaders header = new HttpHeaders(); 	
			header.set("Content-Type", "application/json");
			header.set("Accept", "application/json");
			header.set("Authorization", "Bearer " + vendorApiKey);
			
			ResponseEntity<String> res = webClient.get()
					.uri(vendorApiUrl+"/games?vendor_key="+vendorGameCode)
					.headers(h -> h.addAll(header))
					.retrieve()
					.toEntity(String.class)
					.block();
			JSONObject resJson = new JSONObject(res.getBody());
			JSONArray games = resJson.getJSONArray("data");
			int length = games.length();
			log.info(LOG_PREFIX+"getGrandGameList length: " + length);
			gameList = new ArrayList<>();
			
			for(int i=0; i<length; i++) {
				GameVo game = new GameVo();
				JSONObject objGame = games.getJSONObject(i);
				game.setVendorIdx(vendorIdx);
				game.setVendorTitle(vendorTitle);
				game.setGameId(objGame.getString("game"));
				
				JSONArray gameNames = objGame.getJSONArray("names");
				for(int n=0; n<gameNames.length(); n++) {
					JSONObject gameName = gameNames.getJSONObject(n);
					if("ko".equals(gameName.getString("language"))){
						game.setGameName(gameName.getString("name"));
					}
					if("en".equals(gameName.getString("language"))){
						game.setGameNameEn(gameName.getString("name"));
					}
				}			
				
				game.setGameImg(objGame.getString("image"));
				gameList.add(game);
			}
			
		} catch(WebClientResponseException e) {
			log.error(LOG_PREFIX+ "getGrandGameList WebClientResponseException: " + e.getMessage());
			log.error(LOG_PREFIX+ "getGrandGameList status code: " + e.getStatusCode().value());
			log.error(LOG_PREFIX+ "getGrandGameList response body: " + e.getResponseBodyAsString());
		} catch (WebClientRequestException rae) {
            if(rae.getCause() instanceof ConnectTimeoutException) {
            	log.error(LOG_PREFIX+ "getGrandGameList ConnectTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof ReadTimeoutException) {
            	log.error(LOG_PREFIX+ "getGrandGameList ReadTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof InterruptedException) {
            	log.error(LOG_PREFIX+ "getGrandGameList InterruptedException::"+rae.getMessage());
            }
		} catch(Exception e) {
			log.info(LOG_PREFIX+"[ERROR] getGrandGameList Exception : " + e.toString());
		}
		
		return gameList;
	}

	@Override
	public List<GameVo> getSevenGameList(String LOG_PREFIX, HashMap<String, Object> apiInfo) {
		List<GameVo> gameList = null;
		long vendorIdx = (long) apiInfo.get("vendorIdx");
		String vendorApiUrl = apiInfo.get("vendorApiUrl").toString();
		String vendorApiId = apiInfo.get("vendorApiId").toString();
		String vendorApiKey = apiInfo.get("vendorApiKey").toString();
		String vendorGameCode = apiInfo.get("vendorGameCode").toString();
		String vendorTitle = apiInfo.get("vendorTitle").toString();
		
		try {
			//body
			MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
			parameters.add("vendor", vendorGameCode);
			
			HttpHeaders header = new HttpHeaders(); 	
			header.set("Content-Type", "application/x-www-form-urlencoded");
			header.set("Authorization", vendorApiKey);
			
			log.info(LOG_PREFIX+ "getSevenGameList::Request::"+parameters.toString());
			
			ResponseEntity<String> responseEntity = webClient.post()
																	.uri(vendorApiUrl+"/gamelist")
																	.headers(h -> h.addAll(header))
																	.bodyValue(parameters)
																	.retrieve()
																	.toEntity(String.class)
																	.block();
			JSONObject resJson = new JSONObject(responseEntity.getBody());
			log.info(LOG_PREFIX+ "gameList::Response::"+resJson.toString());
			if(resJson.getInt("code") == 0) {
				log.info(LOG_PREFIX+ "gameList::Response::code::"+resJson.getInt("code"));
				log.info(LOG_PREFIX+ "gameList::Response::msg::"+resJson.getString("msg"));
				JSONArray games = resJson.getJSONArray("data");
				int length = games.length();
				gameList = new ArrayList<>();
				
				for(int i=0; i<length; i++) {
					GameVo game = new GameVo();
					JSONObject objGame = games.getJSONObject(i);
					game.setVendorIdx(vendorIdx);
					game.setVendorTitle(vendorTitle);
					game.setGameId(objGame.getString("game"));
					game.setGameName(objGame.getString("kname"));
					game.setGameNameEn(objGame.getString("name"));
					game.setGameImg(objGame.getString("imageurl"));
					gameList.add(game);
				}
			}
			
		} catch(WebClientResponseException e) {
			log.error(LOG_PREFIX+ "getSevenGameList WebClientResponseException: " + e.getMessage());
			log.error(LOG_PREFIX+ "getSevenGameList status code: " + e.getStatusCode().value());
			log.error(LOG_PREFIX+ "getSevenGameList response body: " + e.getResponseBodyAsString());
		} catch (WebClientRequestException rae) {
            if(rae.getCause() instanceof ConnectTimeoutException) {
            	log.error(LOG_PREFIX+ "getSevenGameList ConnectTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof ReadTimeoutException) {
            	log.error(LOG_PREFIX+ "getSevenGameList ReadTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof InterruptedException) {
            	log.error(LOG_PREFIX+ "getSevenGameList InterruptedException::"+rae.getMessage());
            }
		} catch(Exception e) {
			log.info(LOG_PREFIX+"[ERROR] getSevenGameList Exception : " + e.toString());
		}
		
		return gameList;
	}

	@Override
	public List<GameVo> getTplusGameList(String LOG_PREFIX, HashMap<String, Object> apiInfo) {
		List<GameVo> gameList = null;
		long vendorIdx = (long) apiInfo.get("vendorIdx");
		String vendorApiUrl = apiInfo.get("vendorApiUrl").toString();
		String vendorApiId = apiInfo.get("vendorApiId").toString();
		String vendorApiKey = apiInfo.get("vendorApiKey").toString();
		String vendorGameCode = apiInfo.get("vendorGameCode").toString();
		String vendorTitle = apiInfo.get("vendorTitle").toString();
		
		try {
			HttpHeaders header = new HttpHeaders(); 
			header.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
			header.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
			header.set("Authorization", "Bearer "+vendorApiKey);
			
			UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(vendorApiUrl + "/Games");
			MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
			params.add("thirdparty", vendorGameCode);
			
			ResponseEntity<String> response = webClient.post()
					.uri(builder.toUriString())
					.headers(h -> h.addAll(header))
					.bodyValue(params)
					.retrieve()
					.toEntity(String.class)
					.block();
			JSONObject resJson = new JSONObject(response.getBody());
			if(resJson.getInt("code") == 0) {
				log.info(LOG_PREFIX+ "getTplusGameList result: " + resJson.getString("message"));
				gameList = new ArrayList<>();
				JSONArray games = resJson.getJSONArray("data");
				int length = games.length();
				
				for(int i=0; i<length; i++) {
					GameVo game = new GameVo();
					JSONObject objGame = games.getJSONObject(i);
					game.setVendorIdx(vendorIdx);
					game.setVendorTitle(vendorTitle);
					game.setGameId(objGame.getString("uuid"));
					game.setGameName(objGame.getString("name_kr"));
					game.setGameNameEn(objGame.getString("name_en"));
					game.setGameImg(objGame.getString("image"));
					gameList.add(game);
				}
				
			} else {
				log.error(LOG_PREFIX+ "[ERROR] getTplusGameList code: " + resJson.getInt("code"));
				log.error(LOG_PREFIX+ "[ERROR] getTplusGameList message: " + resJson.getString("message"));
			}
		} catch(WebClientResponseException e) {
			log.error(LOG_PREFIX+ "getTplusGameList WebClientResponseException: " + e.getMessage());
			log.error(LOG_PREFIX+ "getTplusGameList status code: " + e.getStatusCode().value());
			log.error(LOG_PREFIX+ "getTplusGameList response body: " + e.getResponseBodyAsString());
		} catch (WebClientRequestException rae) {
            if(rae.getCause() instanceof ConnectTimeoutException) {
            	log.error(LOG_PREFIX+ "getTplusGameList ConnectTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof ReadTimeoutException) {
            	log.error(LOG_PREFIX+ "getTplusGameList ReadTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof InterruptedException) {
            	log.error(LOG_PREFIX+ "getTplusGameList InterruptedException::"+rae.getMessage());
            }
		} catch(Exception e) {
			log.info(LOG_PREFIX+"[ERROR] getTplusGameList Exception : " + e.toString());
		}
		
		return gameList;
	}

	@Override
	public List<GameVo> getPracpGameList(String LOG_PREFIX, HashMap<String, Object> apiInfo) {
		List<GameVo> gameList = null;
		long vendorIdx = (long) apiInfo.get("vendorIdx");
		String vendorApiUrl = apiInfo.get("vendorApiUrl").toString();
		String vendorApiId = apiInfo.get("vendorApiId").toString();
		String vendorApiKey = apiInfo.get("vendorApiKey").toString();
		String vendorGameCode = apiInfo.get("vendorGameCode").toString();
		String vendorTitle = apiInfo.get("vendorTitle").toString();
		
		try {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(MediaType.APPLICATION_JSON);
			headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
			headers.setAcceptCharset(Arrays.asList(Charset.forName("UTF-8")));
			
			String apiUrl = vendorApiUrl + "/app/game/list?";
			
			SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
			long timeStampL = System.currentTimeMillis();
			String timeStamp = sdf.format(timeStampL);
			apiInfo.put("timeStamp", timeStamp);
			
			String apiKey = "";
			String apiAgentCode = vendorApiId;
			String apiToken = vendorApiKey;
			
			log.info(LOG_PREFIX+ "apiAgentCode::"+apiAgentCode);
			log.info(LOG_PREFIX+ "apiToken::"+apiToken);
			log.info(LOG_PREFIX+ "timeStamp::"+timeStamp);
			
			String textA = apiAgentCode+apiToken+timeStamp;
			String salt = apiToken;
			String textB = textA+salt;
			log.info(LOG_PREFIX+ "textB::"+textB);
			
			try {
				MessageDigest md = MessageDigest.getInstance("SHA-256");
			    md.update(textB.getBytes("UTF-8"));
			    byte[] digest = md.digest();
			    apiKey = new BigInteger(1, digest).toString(16).toLowerCase();
			    log.info(LOG_PREFIX+ "apiKey::"+apiKey);
			} catch(Exception e) {
				log.error(LOG_PREFIX+ "Exception::"+e.getMessage());
			}
			
			String param = "api_key="+apiKey+"&timestamp="+timeStamp
				+"&agent_code="+vendorApiId+"&provider_code="+vendorGameCode;
			apiUrl = apiUrl + param;
			log.info(LOG_PREFIX+ "apiUrl::"+apiUrl);
			
			ResponseEntity<String> resEntity = webClient.get()
					.uri(apiUrl)
					.headers(h -> h.addAll(headers))
					.retrieve()
					.toEntity(String.class)
					.block();
			if(resEntity.getStatusCodeValue() == 200) {
				JSONObject responseObj = new JSONObject(resEntity.getBody());
				log.info(LOG_PREFIX+ "Response : " + responseObj.toString());
				
				JSONArray games = responseObj.getJSONArray("data");
				int length = games.length();
				gameList = new ArrayList<>();
				
				for(int i=0; i<length; i++) {
					GameVo game = new GameVo();
					JSONObject objGame = games.getJSONObject(i);
					String type = objGame.getString("type");
					
					if("slot".equals(type.toLowerCase())) {
						//log.info(objGame.toString());
						game.setVendorIdx(vendorIdx);
						game.setVendorTitle(vendorTitle);
						game.setGameId(objGame.getString("code"));
						game.setGameName(objGame.getString("name"));
						game.setGameNameEn(objGame.getString("en_name"));
						game.setGameImg(objGame.getString("game_img"));
						gameList.add(game);
					}
				}
			}
			
		} catch(WebClientResponseException e) {
			log.error(LOG_PREFIX+ "getPracpGameList WebClientResponseException: " + e.getMessage());
			log.error(LOG_PREFIX+ "getPracpGameList status code: " + e.getStatusCode().value());
			log.error(LOG_PREFIX+ "getPracpGameList response body: " + e.getResponseBodyAsString());
		} catch (WebClientRequestException rae) {
            if(rae.getCause() instanceof ConnectTimeoutException) {
            	log.error(LOG_PREFIX+ "getPracpGameList ConnectTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof ReadTimeoutException) {
            	log.error(LOG_PREFIX+ "getPracpGameList ReadTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof InterruptedException) {
            	log.error(LOG_PREFIX+ "getPracpGameList InterruptedException::"+rae.getMessage());
            }
		} catch(Exception e) {
			log.info(LOG_PREFIX+"[ERROR] getPracpGameList Exception : " + e.toString());
		}
		
		return gameList;
	}
	
	
	private String getHashCode(String LOG_PREFIX, String body, String secretKey) {
		String hashCode = "";
		LOG_PREFIX = LOG_PREFIX + "::getHashCode::";
		try {
			// Json String Body + Secret Key
			String result = body + secretKey;
			// String result = "{\"username\":\"057007mptest01\",\"nickname\":\"007mptest01\",\"siteUsername\":\"057007mptest01\"}";
			log.info(LOG_PREFIX+ "Body + Secret Key::"+result);
			// SHA-256 Hash make
			MessageDigest digestObj = MessageDigest.getInstance("SHA-256");
			byte[] hash_data = digestObj.digest(result.getBytes("UTF-8"));
			
			// Base64 encoding
			hashCode = Base64.getEncoder().encodeToString(hash_data);
			log.info(LOG_PREFIX+ "hashCode::"+hashCode);
		} catch(Exception e) {
			log.error("#-NexusService::getHashCode::Exception::"+e.getMessage());
		}
		
		return hashCode;
	}

	@Override
	public List<GameVo> getNexusGameList(String LOG_PREFIX, HashMap<String, Object> apiInfo) {
		List<GameVo> gameList = null;
		long vendorIdx = (long) apiInfo.get("vendorIdx");
		String apiBaseUrl = apiInfo.get("vendorApiUrl").toString();
		String apiAgentId = apiInfo.get("vendorApiId").toString();
		String apiAgentSecretKey = apiInfo.get("vendorApiKey").toString();
		String apiVendorKey = apiInfo.get("vendorGameCode").toString();
		String vendorTitle = apiInfo.get("vendorTitle").toString();
		
		try {
			JSONObject bodyObj = new JSONObject();
			bodyObj.put("vendorKey", apiVendorKey);
			bodyObj.put("skin", "SLOT");
			bodyObj.put("type", "Slot");
			String bodyJson = bodyObj.toString();
			log.info(LOG_PREFIX+ "bodyJson::"+bodyJson);
			
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
			headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
			headers.setAcceptCharset(Arrays.asList(Charset.forName("UTF-8")));
			String hashCode = getHashCode(LOG_PREFIX, bodyJson, apiAgentSecretKey);
			headers.set("hash", hashCode);
			headers.set("agent", apiAgentId);
			log.info(LOG_PREFIX+ "HttpHeaders::"+headers.toString());
			
			UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(apiBaseUrl + "/games");
			MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
			params.add("vendorKey", apiVendorKey);
			params.add("skin", "SLOT");
			params.add("type", "Slot");
			
			ResponseEntity<String> response = webClient.post()
					.uri(uriBuilder.toUriString())
					.headers(h -> h.addAll(headers))
					.bodyValue(params)
					.retrieve()
					.toEntity(String.class)
					.block();
			JSONObject resObj = new JSONObject(response.getBody());
			if(resObj.getInt("code") == 0) {
				JSONArray games = resObj.getJSONArray("games");
				int length = games.length();
				gameList = new ArrayList<>();
				
				for(int i=0; i<length; i++) {
					GameVo game = new GameVo();
					JSONObject objGame = games.getJSONObject(i);
					JSONObject objName = objGame.getJSONObject("names");
					game.setVendorIdx(vendorIdx);
					game.setVendorTitle(vendorTitle);
					game.setGameId(objGame.getString("key"));
					game.setGameName(objName.getString("ko"));
					game.setGameNameEn(objName.getString("en"));
					game.setGameImg(objGame.getString("image"));
					gameList.add(game);
				}
			}
			
		} catch(WebClientResponseException e) {
			log.error(LOG_PREFIX+ "getNexusGameList WebClientResponseException: " + e.getMessage());
			log.error(LOG_PREFIX+ "getNexusGameList status code: " + e.getStatusCode().value());
			log.error(LOG_PREFIX+ "getNexusGameList response body: " + e.getResponseBodyAsString());
		} catch (WebClientRequestException rae) {
            if(rae.getCause() instanceof ConnectTimeoutException) {
            	log.error(LOG_PREFIX+ "getNexusGameList ConnectTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof ReadTimeoutException) {
            	log.error(LOG_PREFIX+ "getNexusGameList ReadTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof InterruptedException) {
            	log.error(LOG_PREFIX+ "getNexusGameList InterruptedException::"+rae.getMessage());
            }
		} catch(Exception e) {
			log.info(LOG_PREFIX+"[ERROR] getNexusGameList Exception : " + e.toString());
		}
		
		return gameList;
	}

	@Override
	public List<GameVo> getTowerGameList(String LOG_PREFIX, HashMap apiInfo) {
		// https://to-api.com/v2/games?site_code=tripleopr01&vendorCode=pp
		List<GameVo> gameList = null;
		long vendorIdx = (long) apiInfo.get("vendorIdx");
		String vendorTitle = apiInfo.get("vendorTitle").toString();
		String apiBaseUrl = apiInfo.get("vendorApiUrl").toString();
		String apiAgentId = apiInfo.get("vendorApiId").toString();
		String apiAgentSecretKey = apiInfo.get("vendorApiKey").toString();
		String apiVendorKey = apiInfo.get("vendorGameCode").toString();
		
		try {
			HttpHeaders header = new HttpHeaders(); 	
			header.set("Authorization", apiAgentSecretKey);
			
			ResponseEntity<String> responseEntity = webClient.get()
						.uri(apiBaseUrl+"/v2/games?site_code="+apiAgentId+"&vendorCode="+apiVendorKey)
						.headers(h -> h.addAll(header))
						.retrieve()
						.toEntity(String.class)
						.block();
			
			JSONArray games = new JSONArray(responseEntity.getBody());
			int length = games.length();
			log.info(LOG_PREFIX+ "TOWER_API::gameList::Game List length: " + length);
			
			if(length > 0) {
				gameList = new ArrayList<>();
				for(int i=0; i<length; i++) {
					GameVo game = new GameVo();
					JSONObject objGame = games.getJSONObject(i);
					game.setVendorIdx(vendorIdx);
					game.setVendorTitle(vendorTitle);
					game.setGameId(objGame.getString("gameCode"));
					game.setGameName(objGame.getString("name"));
					game.setGameNameEn(objGame.getString("name"));
					game.setGameImg(objGame.getString("img"));
					gameList.add(game);
				}
			} else {
				log.error(LOG_PREFIX+ "TOWER_API::gameList::Game List Empty");
			}
		
		} catch(WebClientResponseException e) {
			log.error(LOG_PREFIX+ "TOWER_API::gameList::WebClientResponseException: " + e.getMessage());
			log.error(LOG_PREFIX+ "TOWER_API::gameList::status code: " + e.getStatusCode().value());
			log.error(LOG_PREFIX+ "TOWER_API::gameList::response body: " + e.getResponseBodyAsString());
		} catch (WebClientRequestException rae) {
            if(rae.getCause() instanceof ConnectTimeoutException) {
            	log.error(LOG_PREFIX+ "TOWER_API::gameList::ConnectTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof ReadTimeoutException) {
            	log.error(LOG_PREFIX+ "TOWER_API::gameList::ReadTimeoutException::"+rae.getMessage());
            }
            if(rae.getCause() instanceof InterruptedException) {
            	log.error(LOG_PREFIX+ "TOWER_API::gameList::InterruptedException::"+rae.getMessage());
            }
		} catch (Exception e) {
			log.error(LOG_PREFIX+ "TOWER_API::gameList::Exception::"+e.toString());
			e.printStackTrace();
        }
		
		return gameList;
	}

}
