package com.bb.api;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jakarta.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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 com.bb.jwt.JwtManager;
import com.bb.model.ApiResponse;
import com.bb.model.BlockGameVO;
import com.bb.model.CmnSearch;
import com.bb.model.Game;
import com.bb.model.GameVo;
import com.bb.model.Site;
import com.bb.service.CommonService;
import com.bb.service.SettingService;
import com.bb.service.SiteService;
import com.bb.util.IPKit;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

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

	@Autowired
	SiteService siteService;
	
	@Autowired
	SettingService settingService;
	
	@Autowired
	CommonService commonService;
	
	@Autowired
	private final JwtManager jwtManager;
	
	
	@ResponseBody	
	@PostMapping("/vendor-selectbox")
    public ApiResponse vendorSelectBox(@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::BLOCK::vendorSelectBox::"+tokenInfo.getSid()+"::::";
				
				// 여기서 부터 로직
				List<HashMap<String, Object>> list = settingService.getBlockVendorSelectBoxList("CASINO");
				log.info(LOG_PREFIX + "Block-Vendor-SelectBoxList cnt::"+list.size());
				
				responseData.put("list", list);
				
				
			} catch(Exception e) {
				e.printStackTrace();
				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("/table-selectbox")
    public ApiResponse tableSelectBox(@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::BLOCK::tableSelectBox::"+tokenInfo.getSid()+"::::";
				search.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "Request Param::"+search);
				List<HashMap<String, Object>> list = settingService.getBlockTableSelectBoxList(search);
				log.info(LOG_PREFIX + "Block-Table-SelectBoxList cnt::"+list.size());
				
				responseData.put("list", list);
				
				
			} catch(Exception e) {
				e.printStackTrace();
				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("/table-list")
    public ApiResponse blockTableList(@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::BLOCK::blockTableList::"+tokenInfo.getSid()+"::::";
				search.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "Request Param::"+search);
				List<HashMap<String, Object>> list = settingService.getBlockTableSelectBoxList(search);
				List<HashMap<String, Object>> mylist = new ArrayList<HashMap<String,Object>>();
				String blockTableIds = settingService.getBlockTableIds(search);
				if(blockTableIds == null) blockTableIds = "";
				//String[] blockTableArr = blockTableIds.split("|");
				for(HashMap<String, Object> item : list) {
					String tableId = item.get("tableId").toString()+"|";
					if(!"".equals(blockTableIds) && blockTableIds.contains(tableId)) {
						mylist.add(item);
					}
				}
				
				responseData.put("list", mylist);
				responseData.put("blockTableIds", blockTableIds);
				
				
			} 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("/table/save")
    public ApiResponse blockGameSave(@RequestHeader String token, HttpServletRequest request, @RequestBody BlockGameVO param) 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::BLOCK::blockGameSave::"+tokenInfo.getSid()+"::::";
				param.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "BF::BlockGameVO::"+param);
				CmnSearch search = new CmnSearch();
				search.setSiteIdx(param.getSiteIdx());
				search.setVendorIdx(param.getVendorIdx());
				
				String vendorTitle = settingService.getVendorTitle(search);
				if(vendorTitle == null || "".equals(vendorTitle)) {
					log.error(LOG_PREFIX+ "VendorTitle is not null or empty");
					apiResponse.setResultCode("99");
					apiResponse.setResultMessage("VendorTitle is not null or empty");
					return apiResponse;
				}
				param.setVendorTitle(vendorTitle);
				
				String blockTableIds = settingService.getBlockTableIds(search);
				if(blockTableIds == null) blockTableIds = "";
				log.info(LOG_PREFIX +"BF::blockTableIds::" + blockTableIds);
				
				if(!"".equals(blockTableIds) && blockTableIds.contains(param.getBlockTableId())) {
					log.info(LOG_PREFIX + param.getBlockTableId() + " is already saved");
				} else {
					blockTableIds = blockTableIds + param.getBlockTableId() + "|";
					log.info(LOG_PREFIX +"AF::blockTableIds::" + blockTableIds);
					param.setBlockTableIds(blockTableIds);
					log.info(LOG_PREFIX +"AF::BlockGameVO::" + param);
					int saveResult = settingService.blockTableIdSave(param);
					log.info(LOG_PREFIX + "blockTableIdSave result::"+saveResult);
				}
				
			} catch(Exception e) {
				log.info(e.toString());
				apiResponse.setResultCode("99995");
				apiResponse.setResultMessage("token is no valid");
				return apiResponse;
			}
			
			apiResponse.success();
			
		} catch (Exception e) {
			e.printStackTrace();
			apiResponse.fail();
		}
		
		return apiResponse;
	}
	
	
	@ResponseBody	
	@PostMapping("/table/delete")
    public ApiResponse blockGameDelete(@RequestHeader String token, HttpServletRequest request, @RequestBody BlockGameVO param) 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::BLOCK::blockGameDelete::"+tokenInfo.getSid()+"::::";
				param.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "BF::BlockGameVO::"+param);
				CmnSearch search = new CmnSearch();
				search.setSiteIdx(param.getSiteIdx());
				search.setVendorIdx(param.getVendorIdx());
				
				String vendorTitle = settingService.getVendorTitle(search);
				if(vendorTitle == null || "".equals(vendorTitle)) {
					log.error(LOG_PREFIX+ "VendorTitle is not null or empty");
					apiResponse.setResultCode("99");
					apiResponse.setResultMessage("VendorTitle is not null or empty");
					return apiResponse;
				}
				param.setVendorTitle(vendorTitle);
				
				String blockTableIds = settingService.getBlockTableIds(search);
				if(blockTableIds == null) blockTableIds = "";
				log.info(LOG_PREFIX +"BF::blockTableIds::" + blockTableIds);
				
				if(!"".equals(blockTableIds) && !blockTableIds.contains(param.getBlockTableId())) {
					log.info(LOG_PREFIX + param.getBlockTableId() + " is not found");
				} else {
					blockTableIds = blockTableIds.replace(param.getBlockTableId() + "|", "");
					log.info(LOG_PREFIX +"AF::blockTableIds::" + blockTableIds);
					param.setBlockTableIds(blockTableIds);
					log.info(LOG_PREFIX +"AF::BlockGameVO::" + param);
					int saveResult = settingService.blockTableIdSave(param);
					log.info(LOG_PREFIX + "blockTableIdSave result::"+saveResult);
				}
				
			} catch(Exception e) {
				log.info(e.toString());
				apiResponse.setResultCode("99995");
				apiResponse.setResultMessage("token is no valid");
				return apiResponse;
			}
			
			apiResponse.success();
			
		} catch (Exception e) {
			e.printStackTrace();
			apiResponse.fail();
		}
		
		return apiResponse;
	}
	
	
	@ResponseBody	
	@PostMapping("/slotVendors")
    public ApiResponse slotVendors(@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::BLOCK::slotVendors::"+tokenInfo.getSid()+"::::";
				
				CmnSearch search = new CmnSearch();
				search.setSiteIdx((long) site.getSiteIdx());
				search.setCategory("SLOT");
				
				// 여기서 부터 로직
				List<HashMap<String, Object>> list = settingService.getBlockVendorSelectBoxList2(search);
				
				responseData.put("list", list);
				
				
			} catch(Exception e) {
				e.printStackTrace();
				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("/slotGames")
    public ApiResponse slotGames(@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::BLOCK::slotGames::"+tokenInfo.getSid()+"::::";
				search.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "Request Param::"+search);
				
				HashMap apiInfo = commonService.getVendorApiInfo(search);
				log.info(LOG_PREFIX + "API Info::"+apiInfo.toString());
				// -- grand, svendor, tower, tplus
				List<GameVo> gameList = null;
				if("grand".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getGrandGameList(LOG_PREFIX, apiInfo);
				} else if("svendor".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getSevenGameList(LOG_PREFIX, apiInfo);
				} else if("pink".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getSevenGameList(LOG_PREFIX, apiInfo);
				} else if("tplus".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getTplusGameList(LOG_PREFIX, apiInfo);
				} else if("pracp".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getPracpGameList(LOG_PREFIX, apiInfo);
				} else if("nexus".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getNexusGameList(LOG_PREFIX, apiInfo);
				} else if("ace2".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getNexusGameList(LOG_PREFIX, apiInfo);
				} else if("tower".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getTowerGameList(LOG_PREFIX, apiInfo);
				} else {
					log.error(LOG_PREFIX + "Not found vendor company");
				}
				
				responseData.put("list", gameList);
				
			} catch(Exception e) {
				e.printStackTrace();
				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("/slot-block/gameList")
    public ApiResponse slotBlockGameList(@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::BLOCK::slotGames::"+tokenInfo.getSid()+"::::";
				search.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "Request Param::"+search);
				
				HashMap apiInfo = commonService.getVendorApiInfo(search);
				log.info(LOG_PREFIX + "API Info::"+apiInfo.toString());
				// -- grand, svendor, tower, tplus
				List<GameVo> gameList = null;
				if("grand".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getGrandGameList(LOG_PREFIX, apiInfo);
				} else if("svendor".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getSevenGameList(LOG_PREFIX, apiInfo);
				} else if("pink".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getSevenGameList(LOG_PREFIX, apiInfo);
				} else if("tplus".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getTplusGameList(LOG_PREFIX, apiInfo);
				} else if("pracp".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getPracpGameList(LOG_PREFIX, apiInfo);
				} else if("nexus".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getNexusGameList(LOG_PREFIX, apiInfo);
				} else if("ace2".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getNexusGameList(LOG_PREFIX, apiInfo);
				} else if("tower".equals(apiInfo.get("vendorTitle").toString())) {
					gameList = commonService.getTowerGameList(LOG_PREFIX, apiInfo);
				} else {
					log.error(LOG_PREFIX + "Not found vendor company");
				}
				
				List<GameVo> mylist = new ArrayList<>();
				String blockTableIds = settingService.getBlockTableIds(search);
				if(blockTableIds == null) blockTableIds = "";
				//String[] blockTableArr = blockTableIds.split("|");
				for(GameVo item : gameList) {
					String tableId = item.getGameId()+"|";
					if(!"".equals(blockTableIds) && blockTableIds.contains(tableId)) {
						mylist.add(item);
					}
				}
				
				responseData.put("list", mylist);
				responseData.put("blockTableIds", blockTableIds);
				
			} 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("/slot-block/save")
    public ApiResponse SlotBlockSave(@RequestHeader String token, HttpServletRequest request, @RequestBody BlockGameVO param) 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::BLOCK::SlotBlockSave::"+tokenInfo.getSid()+"::::";
				param.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "BF::BlockGameVO::"+param);
				CmnSearch search = new CmnSearch();
				search.setSiteIdx(param.getSiteIdx());
				search.setVendorIdx(param.getVendorIdx());
				
				String blockTableIds = settingService.getBlockTableIds(search);
				if(blockTableIds == null) blockTableIds = "";
				log.info(LOG_PREFIX +"BF::blockTableIds::" + blockTableIds);
				
				if(!"".equals(blockTableIds) && blockTableIds.contains(param.getBlockTableId())) {
					log.info(LOG_PREFIX + param.getBlockTableId() + " is already saved");
				} else {
					blockTableIds = blockTableIds + param.getBlockTableId() + "|";
					log.info(LOG_PREFIX +"AF::blockTableIds::" + blockTableIds);
					param.setBlockTableIds(blockTableIds);
					log.info(LOG_PREFIX +"AF::BlockGameVO::" + param);
					int saveResult = settingService.blockTableIdSave(param);
					log.info(LOG_PREFIX + "blockTableIdSave result::"+saveResult);
				}
				
			} catch(Exception e) {
				log.info(e.toString());
				apiResponse.setResultCode("99995");
				apiResponse.setResultMessage("token is no valid");
				return apiResponse;
			}
			
			apiResponse.success();
			
		} catch (Exception e) {
			e.printStackTrace();
			apiResponse.fail();
		}
		
		return apiResponse;
	}
	
	
	@ResponseBody	
	@PostMapping("/slot-block/delete")
    public ApiResponse SlotBlockDelete(@RequestHeader String token, HttpServletRequest request, @RequestBody BlockGameVO param) 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::BLOCK::SlotBlockDelete::"+tokenInfo.getSid()+"::::";
				param.setSiteIdx((long) site.getSiteIdx());
				
				// 여기서 부터 로직
				log.info(LOG_PREFIX + "BF::BlockGameVO::"+param);
				CmnSearch search = new CmnSearch();
				search.setSiteIdx(param.getSiteIdx());
				search.setVendorIdx(param.getVendorIdx());
				
				String blockTableIds = settingService.getBlockTableIds(search);
				if(blockTableIds == null) blockTableIds = "";
				log.info(LOG_PREFIX +"BF::blockTableIds::" + blockTableIds);
				
				if(!"".equals(blockTableIds) && !blockTableIds.contains(param.getBlockTableId())) {
					log.info(LOG_PREFIX + param.getBlockTableId() + " is not found");
				} else {
					blockTableIds = blockTableIds.replace(param.getBlockTableId() + "|", "");
					log.info(LOG_PREFIX +"AF::blockTableIds::" + blockTableIds);
					param.setBlockTableIds(blockTableIds);
					log.info(LOG_PREFIX +"AF::BlockGameVO::" + param);
					int saveResult = settingService.blockTableIdSave(param);
					log.info(LOG_PREFIX + "blockTableIdSave result::"+saveResult);
				}
				
			} catch(Exception e) {
				log.info(e.toString());
				apiResponse.setResultCode("99995");
				apiResponse.setResultMessage("token is no valid");
				return apiResponse;
			}
			
			apiResponse.success();
			
		} catch (Exception e) {
			e.printStackTrace();
			apiResponse.fail();
		}
		
		return apiResponse;
	}
	
}
