package com.bb.api;

import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
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.exception.ApiException;
import com.bb.jwt.JwtManager;
import com.bb.model.ApiResponse;
import com.bb.model.BanGameSearch;
import com.bb.model.CmnSearch;
import com.bb.model.Site;
import com.bb.service.CommonService;
import com.bb.service.SiteService;
import com.bb.util.IPKit;

import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequiredArgsConstructor
@RequestMapping(value = "/api/v1/cmn")
public class ApiCommonController {

	@Autowired
	SiteService siteService;

	@Autowired
	CommonService commonService;

	@Autowired
	WebClient webClient;

	@Autowired
	private final JwtManager jwtManager;

	@ResponseBody
	@PostMapping("/code/category")
	public ApiResponse gameCategoryList(@RequestHeader String token, HttpServletRequest request) throws Exception {
		ApiResponse apiResponse = new ApiResponse();

		try {
			Site site = siteService.getSiteInfoAPI(request);
			if (site == null) {
				apiResponse.setResultCode("9999");
				apiResponse.setResultMessage("Authorization apiKey check");
				return apiResponse;
			}

			if (!(site.getSiteIp() == null || "".equals(site.getSiteIp()) || "3.3.3.3".equals(site.getSiteIp())
					|| site.getSiteIp().indexOf(IPKit.getIpAddressByRequest(request)) >= 0)) {
				log.error("site.getSiteIp(" + site.getSiteIp() + "), denied" + IPKit.getIpAddressByRequest(request));
				apiResponse.setResultCode("10001");
				return apiResponse;
			}

			// TO DO 토큰체크
			Map responseData = new HashMap();

			try {
				JwtManager.TokenInfo tokenInfo = jwtManager.getTokenInfoAdmin(token);
				final String LOG_PREFIX = "#-API::CMN::gameCategoryList::" + tokenInfo.getSid() + "::::";

				// 여기서 부터 로직
				log.info(LOG_PREFIX);

				List<HashMap<String, String>> list = commonService.getGameCategoryList();
				responseData.put("list", list);

			} catch (Exception e) {
				log.info(e.toString());
				apiResponse.setResultCode("99995");
				apiResponse.setResultMessage("token is no valid");
				return apiResponse;
			}

			apiResponse.setData(responseData);
			apiResponse.success();

		} catch (Exception e) {
			e.printStackTrace();
			apiResponse.fail();
		}

		return apiResponse;
	}

	@ResponseBody
	@PostMapping("/code/vendor")
	public ApiResponse gameVendorList(@RequestHeader String token, HttpServletRequest request,
			@RequestBody CmnSearch search) throws Exception {
		ApiResponse apiResponse = new ApiResponse();

		try {
			Site site = siteService.getSiteInfoAPI(request);
			if (site == null) {
				apiResponse.setResultCode("9999");
				apiResponse.setResultMessage("Authorization apiKey check");
				return apiResponse;
			}

			if (!(site.getSiteIp() == null || "".equals(site.getSiteIp()) || "3.3.3.3".equals(site.getSiteIp())
					|| site.getSiteIp().indexOf(IPKit.getIpAddressByRequest(request)) >= 0)) {
				log.error("site.getSiteIp(" + site.getSiteIp() + "), denied" + IPKit.getIpAddressByRequest(request));
				apiResponse.setResultCode("10001");
				return apiResponse;
			}

			// TO DO 토큰체크
			Map responseData = new HashMap();

			try {
				JwtManager.TokenInfo tokenInfo = jwtManager.getTokenInfoAdmin(token);
				final String LOG_PREFIX = "#-API::CMN::gameVendorList::" + tokenInfo.getSid() + "::::";

				// 여기서 부터 로직
				log.info(LOG_PREFIX);

				List<HashMap<String, Object>> list = commonService.getGameVendorList(search);
				responseData.put("list", list);

			} catch (Exception e) {
				log.info(e.toString());
				apiResponse.setResultCode("99995");
				apiResponse.setResultMessage("token is no valid");
				return apiResponse;
			}

			apiResponse.setData(responseData);
			apiResponse.success();

		} catch (Exception e) {
			e.printStackTrace();
			apiResponse.fail();
		}

		return apiResponse;
	}

	@ResponseBody
	@GetMapping("/banGameSet/{vendorTitle}/{vendorIdx}/{skin}")
	public ApiResponse banGameSetByGet(@RequestHeader String token, HttpServletRequest request,
			@PathVariable("vendorTitle") String vendorTitle, @PathVariable("vendorIdx") Long vendorIdx,
			@PathVariable("skin") String skin) throws Exception {
		ApiResponse apiResponse = new ApiResponse();

		try {
			Site site = siteService.getSiteInfoAPI(request);
			if (site == null) {
				apiResponse.setResultCode("9999");
				apiResponse.setResultMessage("Authorization apiKey check");
				return apiResponse;
			}

			if (!(site.getSiteIp() == null || "".equals(site.getSiteIp()) || "3.3.3.3".equals(site.getSiteIp())
					|| site.getSiteIp().indexOf(IPKit.getIpAddressByRequest(request)) >= 0)) {
				log.error("site.getSiteIp(" + site.getSiteIp() + "), denied" + IPKit.getIpAddressByRequest(request));
				apiResponse.setResultCode("10001");
				return apiResponse;
			}

			// TO DO 토큰체크
			Map responseData = new HashMap();

			try {
				JwtManager.TokenInfo tokenInfo = jwtManager.getTokenInfoAdmin(token);
				final String LOG_PREFIX = "#-API::CMN::banGameSetByGet::" + tokenInfo.getSid() + "::::";

				BanGameSearch search = new BanGameSearch();
				search.setVendorTitle(vendorTitle);
				search.setVendorIdx(vendorIdx);
				search.setSkin(skin);

				// 여기서 부터 로직
				log.info(LOG_PREFIX + "BanGameSearch : " + search.toString());

				if (search.getVendorTitle() == null || "".equals(search.getVendorTitle())) {
					apiResponse.setResultCode("-1");
					apiResponse.setResultMessage("vendorTitle is not empty");
					return apiResponse;
				}

				List<HashMap<String, Object>> banGameList = commonService.getBanGameList(search);
				if (banGameList == null || banGameList.size() == 0) {
					apiResponse.setResultCode("-2");
					apiResponse.setResultMessage("banGameList empty");
					return apiResponse;
				}

				log.info(LOG_PREFIX + "BanGameSearch : " + banGameList.toString());

				if ("nexus".equals(search.getVendorTitle())) {
					HashMap<String, Object> apiInfo = banGameList.get(0);
					String apiBaseUrl = apiInfo.get("apiBaseUrl").toString();
					String apiAgentId = apiInfo.get("apiAgentId").toString();
					String apiKey = apiInfo.get("apiSecretKey").toString();

					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")));

					for (HashMap<String, Object> item : banGameList) {
						String apiVendorKey = item.get("apiVendorCode").toString();
						String vendorCetegory = item.get("vendorCetegory").toString();

						JSONObject bodyObj = new JSONObject();
						bodyObj.put("vendorKey", apiVendorKey);
						if (vendorCetegory.equals("CASINO")) {
							if (search.getSkin() == null || search.getSkin().equals(""))
								search.setSkin("B");
							bodyObj.put("skin", search.getSkin());
						} else if (vendorCetegory.equals("SLOT")) {
							bodyObj.put("skin", "SLOT");
							bodyObj.put("type", "Slot");
							search.setSkin("");
						} else {

						}
						String bodyJson = bodyObj.toString();
						log.info(LOG_PREFIX + "bodyJson::" + bodyJson);

						String hashCode = getHashCode(LOG_PREFIX, bodyJson, apiKey);
						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);
						if (vendorCetegory.equals("CASINO")) {
							params.add("skin", search.getSkin());
						} else if (vendorCetegory.equals("SLOT")) {
							params.add("skin", "SLOT");
							params.add("type", "Slot");
						} else {

						}

						try {
							String responseBody = webClient.post().uri(uriBuilder.toUriString())
									.headers(h -> h.addAll(headers)).bodyValue(params).retrieve()
									.bodyToMono(String.class).block();

							JSONObject resObj = new JSONObject(responseBody);
							if (resObj.getInt("code") == 0) {
								JSONArray games = resObj.getJSONArray("games");
								int length = games.length();

								for (int i = 0; i < length; i++) {
									JSONObject objGame = games.getJSONObject(i);
									JSONObject objName = objGame.getJSONObject("names");

									String gameType = objGame.getString("type");
									String gameId = objGame.getString("id");
									String gameKey = objGame.getString("key");
									String gameTitleEn = objName.getString("en");
									String gameTitleKo = objName.getString("ko");

									item.put("banGameType", gameType);
									item.put("banGameId", gameId);
									item.put("banGameName", gameTitleEn + "||" + gameTitleKo);
									item.put("banGameNameEng", gameTitleEn);
									item.put("banGameKey", gameKey);
									item.put("skin", search.getSkin());

									log.info(LOG_PREFIX + "item : " + item.toString());
									int result = commonService.insertBanGameInfo(item);
									log.info(LOG_PREFIX + "insertBanGameInfo result : " + result);
									/*
									 * if(apiVendorKey.equals("evolution_casino")) { result =
									 * commonService.insertNexusGameInfo(item); log.info(LOG_PREFIX+
									 * "insertNexusGameInfo result : " + result); }
									 */
								}

							} else {
								apiResponse.setResultCode("-99");
								apiResponse.setResultMessage("api fail");
								return apiResponse;
							}
						} catch (WebClientResponseException e) {
							log.error(LOG_PREFIX + "WebClientResponseException : " + e.getMessage());
							throw new ApiException("E901", "API call failed");
						} catch (WebClientRequestException e) {
							log.error(LOG_PREFIX + "WebClientRequestException : " + e.getMessage());
							throw new ApiException("E902", "Network error");
						}
					}

				} else if ("ace2".equals(search.getVendorTitle())) {
					HashMap<String, Object> apiInfo = banGameList.get(0);
					String apiBaseUrl = apiInfo.get("apiBaseUrl").toString();
					String apiAgentId = apiInfo.get("apiAgentId").toString();
					String apiKey = apiInfo.get("apiSecretKey").toString();

					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")));

					for (HashMap<String, Object> item : banGameList) {
						String apiVendorKey = item.get("apiVendorCode").toString();
						String vendorCetegory = item.get("vendorCetegory").toString();

						JSONObject bodyObj = new JSONObject();
						bodyObj.put("vendorKey", apiVendorKey);
						if (vendorCetegory.equals("CASINO")) {
							if (search.getSkin() == null || search.getSkin().equals(""))
								search.setSkin("B");
							bodyObj.put("skin", search.getSkin());
						} else if (vendorCetegory.equals("SLOT")) {
							bodyObj.put("skin", "SLOT");
							bodyObj.put("type", "Slot");
							search.setSkin("");
						} else {

						}
						String bodyJson = bodyObj.toString();
						log.info(LOG_PREFIX + "bodyJson::" + bodyJson);

						String hashCode = getHashCode(LOG_PREFIX, bodyJson, apiKey);
						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);
						if (vendorCetegory.equals("CASINO")) {
							params.add("skin", search.getSkin());
						} else if (vendorCetegory.equals("SLOT")) {
							params.add("skin", "SLOT");
							params.add("type", "Slot");
						} else {

						}

						try {
							String responseBody = webClient.post().uri(uriBuilder.toUriString())
									.headers(h -> h.addAll(headers)).bodyValue(params).retrieve()
									.bodyToMono(String.class).block();

							JSONObject resObj = new JSONObject(responseBody);
							if (resObj.getInt("code") == 0) {
								JSONArray games = resObj.getJSONArray("games");
								int length = games.length();

								for (int i = 0; i < length; i++) {
									JSONObject objGame = games.getJSONObject(i);
									JSONObject objName = objGame.getJSONObject("names");

									String gameType = objGame.getString("type");
									String gameId = objGame.getString("id");
									String gameKey = objGame.getString("key");
									String gameTitleEn = objName.getString("en");
									String gameTitleKo = objName.getString("ko");

									item.put("banGameType", gameType);
									item.put("banGameId", gameId);
									item.put("banGameName", gameTitleEn + "||" + gameTitleKo);
									item.put("banGameNameEng", gameTitleEn);
									item.put("banGameKey", gameKey);
									item.put("skin", search.getSkin());

									log.info(LOG_PREFIX + "item : " + item.toString());
									int result = commonService.insertBanGameInfo(item);
									log.info(LOG_PREFIX + "insertBanGameInfo result : " + result);
									/*
									 * if(apiVendorKey.equals("evolution_casino")) { result =
									 * commonService.insertNexusGameInfo(item); log.info(LOG_PREFIX+
									 * "insertNexusGameInfo result : " + result); }
									 */
								}

							} else {
								apiResponse.setResultCode("-99");
								apiResponse.setResultMessage("api fail");
								return apiResponse;
							}
						} catch (WebClientResponseException e) {
							log.error(LOG_PREFIX + "WebClientResponseException : " + e.getMessage());
							throw new ApiException("E901", "API call failed");
						} catch (WebClientRequestException e) {
							log.error(LOG_PREFIX + "WebClientRequestException : " + e.getMessage());
							throw new ApiException("E902", "Network error");
						}
					}

				} else if ("dpcore".equals(search.getVendorTitle())) {
					HashMap<String, Object> apiInfo = banGameList.get(0);
					String apiBaseUrl = apiInfo.get("apiBaseUrl").toString();
					String apiAgentId = apiInfo.get("apiAgentId").toString();
					String apiKey = "Bearer " + apiInfo.get("apiSecretKey").toString();

					HttpHeaders headers = new HttpHeaders();
					headers.setContentType(MediaType.APPLICATION_JSON);
					headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
					headers.set("Authorization", apiKey);
					String gameUrl = apiBaseUrl + "/api/gameList";

					for (HashMap<String, Object> item : banGameList) {
						String apiVendorKey = item.get("apiVendorCode").toString();
						JSONObject prams = new JSONObject();

						log.info(LOG_PREFIX + "DPCORE::Game List Url: " + gameUrl);
						log.info(LOG_PREFIX + "DPCORE::Game List Headers: " + headers.toString());

						try {
							String responseBody = webClient.post().uri(gameUrl).headers(h -> h.addAll(headers))
									.bodyValue(prams.toString()).retrieve().bodyToMono(String.class).block();

							JSONArray games = new JSONArray(responseBody);
							int length = games.length();

							for (int i = 0; i < length; i++) {
								JSONObject objGame = games.getJSONObject(i);
								String gameType = objGame.getString("gameType");
								String gameId = objGame.getString("tableId");
								String gameKey = objGame.getString("tableId");
								String gameTitleEn = objGame.getString("tableName");
								String gameTitleKo = objGame.getString("tableName");

								item.put("banGameType", gameType);
								item.put("banGameId", gameId);
								item.put("banGameName", gameTitleEn + "||" + gameTitleKo);
								item.put("banGameNameEng", gameTitleEn);
								item.put("banGameKey", gameKey);
								item.put("skin", search.getSkin());

								log.info(LOG_PREFIX + "item : " + item.toString());
								int result = commonService.insertBanGameInfo(item);
								log.info(LOG_PREFIX + "insertBanGameInfo result : " + result);
							}
						} catch (WebClientResponseException e) {
							log.error(LOG_PREFIX + "WebClientResponseException : " + e.getMessage());
							throw new ApiException("E901", "API call failed");
						} catch (WebClientRequestException e) {
							log.error(LOG_PREFIX + "WebClientRequestException : " + e.getMessage());
							throw new ApiException("E902", "Network error");
						}
					}
				} else if ("pink".equals(search.getVendorTitle())) {
					HashMap<String, Object> apiInfo = banGameList.get(0);
					String apiBaseUrl = apiInfo.get("apiBaseUrl").toString();
					String apiAgentId = apiInfo.get("apiAgentId").toString();
					String apiKey = apiInfo.get("apiSecretKey").toString();
					String apiVendorCode = apiInfo.get("apiVendorCode").toString();

					HttpHeaders headers = new HttpHeaders();
					headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
					headers.set("Authorization", apiKey);

					UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(apiBaseUrl + "/gamelist");
					MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
					params.add("vendor", apiVendorCode);
					params.add("type", "all");

					log.info(LOG_PREFIX + "HttpHeaders::" + headers.toString());
					log.info(LOG_PREFIX + "params::" + params.toString());

					try {
						String responseBody = webClient.post().uri(uriBuilder.toUriString())
								.headers(h -> h.addAll(headers)).bodyValue(params).retrieve().bodyToMono(String.class)
								.block();
						JSONObject resObj = new JSONObject(responseBody);

						if (resObj.getInt("code") == 0) {
							log.info(LOG_PREFIX + "gameList::Response::code::" + resObj.getInt("code"));
							log.info(LOG_PREFIX + "gameList::Response::msg::" + resObj.getString("msg"));
							JSONArray games = resObj.getJSONArray("data");
							int length = games.length();

							for (int i = 0; i < length; i++) {
								JSONObject objGame = games.getJSONObject(i);
								String gameType = objGame.getString("type");
								String gameId = objGame.getString("game");
								String gameKey = objGame.getString("game");
								String gameTitleEn = objGame.getString("name");
								String gameTitleKo = objGame.getString("kname");

								apiInfo.put("banGameType", gameType);
								apiInfo.put("banGameId", gameId);
								apiInfo.put("banGameName", gameTitleEn + "||" + gameTitleKo);
								apiInfo.put("banGameNameEng", gameTitleEn);
								apiInfo.put("banGameKey", gameKey);
								apiInfo.put("skin", search.getSkin());

								log.info(LOG_PREFIX + "item : " + apiInfo.toString());
								int result = commonService.insertBanGameInfo(apiInfo);
								log.info(LOG_PREFIX + "insertBanGameInfo result : " + result);
							}
						} else {
							apiResponse.setResultCode("-99");
							apiResponse.setResultMessage("api fail");
							return apiResponse;
						}
					} catch (WebClientResponseException e) {
						log.error(LOG_PREFIX + "WebClientResponseException : " + e.getMessage());
						throw new ApiException("E901", "API call failed");
					} catch (WebClientRequestException e) {
						log.error(LOG_PREFIX + "WebClientRequestException : " + e.getMessage());
						throw new ApiException("E902", "Network error");
					}
				} else if ("onix".equals(search.getVendorTitle())) {
					HashMap<String, Object> apiInfo = banGameList.get(0);
					String apiBaseUrl = apiInfo.get("apiBaseUrl").toString();
					String apiAgentId = apiInfo.get("apiAgentId").toString();
					String apiKey = "Bearer " + apiInfo.get("apiSecretKey").toString();

					HttpHeaders headers = new HttpHeaders();
					headers.setContentType(MediaType.APPLICATION_JSON);
					headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
					headers.set("Authorization", apiKey);
					String gameUrl = apiBaseUrl + "/csapi/Provider";

					for (HashMap<String, Object> item : banGameList) {
						String apiVendorKey = item.get("apiVendorCode").toString();
						JSONObject prams = new JSONObject();
						prams.put("type", "0");
						prams.put("gameid", "SxCasino");
						prams.put("code", "evolution");
						prams.put("gametype", "live");

						log.info(LOG_PREFIX + "ONIX::Game List Url: " + gameUrl);
						log.info(LOG_PREFIX + "ONIX::Game List Headers: " + headers.toString());

						try {
							String responseBody = webClient.post().uri(gameUrl).headers(h -> h.addAll(headers))
									.bodyValue(prams.toString()).retrieve().bodyToMono(String.class).block();
							JSONObject resObj = new JSONObject(responseBody);
							int resultCode = resObj.getInt("result");
							
							if(resultCode == 1) {
								JSONArray games = resObj.getJSONArray("data");
								int length = games.length();

								for (int i = 0; i < length; i++) {
									JSONObject objGame = games.getJSONObject(i);
									String gameType = objGame.getString("type");
									String gameId = objGame.getString("subcode");
									String gameTitleEn = objGame.getString("name_eng");
									String gameTitleKo = objGame.getString("name_kor");

									item.put("banGameType", gameType);
									item.put("banGameId", gameId);
									item.put("banGameName", gameTitleEn + "||" + gameTitleKo);
									item.put("banGameNameEng", gameTitleEn);
									item.put("skin", search.getSkin());

									log.info(LOG_PREFIX + "item : " + item.toString());
									int result = commonService.insertBanGameInfo(item);
									log.info(LOG_PREFIX + "insertBanGameInfo result : " + result);
								}
							}
						} catch (WebClientResponseException e) {
							log.error(LOG_PREFIX + "WebClientResponseException : " + e.getMessage());
							throw new ApiException("E901", "API call failed");
						} catch (WebClientRequestException e) {
							log.error(LOG_PREFIX + "WebClientRequestException : " + e.getMessage());
							throw new ApiException("E902", "Network error");
						}
					}
				}

			} catch (Exception e) {
				log.error("#-API::CMN::banGameSet::" + e.toString());
				e.printStackTrace();
				apiResponse.setResultCode("99995");
				apiResponse.setResultMessage("token is no valid");
				return apiResponse;
			}

			apiResponse.setData(responseData);
			apiResponse.success();

		} catch (Exception e) {
			e.printStackTrace();
			apiResponse.fail();
		}

		return apiResponse;
	}

	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;
	}

}
