package com.bb.admin.controller;

import java.util.HashMap;

import jakarta.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bb.model.Site;
import com.bb.model.SiteSearch;
import com.bb.service.SiteService;

import lombok.extern.slf4j.Slf4j;



@Slf4j
@Controller
@RequestMapping(value = "")
@PreAuthorize("hasRole('ADMIN')")
public class ManualController {
	
	@Autowired
	SiteService siteService;
	
	
	  
	  @GetMapping("/manual")
	  	public String devmanual( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  
		  return "admin/api_doc"; 
		  
	  }
	  
	  @GetMapping("/apiLogdev")
	  	public String devApiLog( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiLogdev"; 
		  
	  }
	  
	  @GetMapping("/apiIntro")
	  	public String devIntro( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiIntro"; 
		  
	  }
	  
	  @GetMapping("/apiGame")
	  	public String devGame( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiGame"; 
		  
	  }
	  
	  @GetMapping("/apiGamelist")
	  	public String devGamelist( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiGamelist"; 
		  
	  }
	  
	  @GetMapping("/apiPartner")
	  	public String devPartner( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiPartner"; 
		  
	  }
	  
	  @GetMapping("/apiBetList")
	  	public String devBetlist( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    
	    	model.put("loginSite", loginSite);
	    	long siteCredit = siteService.getSiteCredit(loginSite.getSiteId());
	    	long underSiteCredit = siteService.getUnderSiteCredit(loginSite.getSiteId());
	    	model.put("underSiteCredit", underSiteCredit);	
	    	model.put("siteCredit", siteCredit);
	    	long sitePoint = siteService.getSitePoint(loginSite.getSiteId());
	    	model.put("sitePoint", sitePoint);	
	    	HashMap creditWait = siteService.getCreditWait(loginSite.getSiteIdx());
	    	model.put("creditWait", creditWait);  
	    	long insureAmt = siteService.getInsureAmt(loginSite.getSiteId());
	    	long insurePointAmt = siteService.getInsurePointAmt(loginSite.getSiteId());	
	    	model.put("insureAmt", insureAmt);	  
	    	model.put("insurePointAmt", insurePointAmt);	



		  return "admin/apiBetList"; 
		  
	  }
	  
	  @GetMapping("/apiBetDetail")
	  	public String devBetDe( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    
	    	model.put("loginSite", loginSite);
	    	long siteCredit = siteService.getSiteCredit(loginSite.getSiteId());
	    	long underSiteCredit = siteService.getUnderSiteCredit(loginSite.getSiteId());
	    	model.put("underSiteCredit", underSiteCredit);	
	    	model.put("siteCredit", siteCredit);
	    	long sitePoint = siteService.getSitePoint(loginSite.getSiteId());
	    	model.put("sitePoint", sitePoint);	
	    	HashMap creditWait = siteService.getCreditWait(loginSite.getSiteIdx());
	    	model.put("creditWait", creditWait);  
	    	long insureAmt = siteService.getInsureAmt(loginSite.getSiteId());
	    	long insurePointAmt = siteService.getInsurePointAmt(loginSite.getSiteId());	
	    	model.put("insureAmt", insureAmt);	  
	    	model.put("insurePointAmt", insurePointAmt);	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiBetDetail"; 
		  
	  }
	  
	  @GetMapping("/apiBetCallback")
	  	public String devBetCall( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiBetCallback"; 
		  
	  }
	  

	  @GetMapping("/apiBetInfo1")
	  	public String devInfo1( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiBetInfo1"; 
		  
	  }
	  
	  @GetMapping("/apiBetInfo2")
	  	public String devInfo2( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    	search.setSiteIdx(loginSite.getSiteIdx());

		  return "admin/apiBetInfo2"; 
		  
	  }
	  
	  
	  
	  	@GetMapping({"/apiAuth"})
	  	public String apiAuth( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    
	    	model.put("loginSite", loginSite);
	    	long siteCredit = siteService.getSiteCredit(loginSite.getSiteId());
	    	long underSiteCredit = siteService.getUnderSiteCredit(loginSite.getSiteId());
	    	model.put("underSiteCredit", underSiteCredit);	
	    	model.put("siteCredit", siteCredit);
	    	long sitePoint = siteService.getSitePoint(loginSite.getSiteId());
	    	model.put("sitePoint", sitePoint);	
	    	HashMap creditWait = siteService.getCreditWait(loginSite.getSiteIdx());
	    	model.put("creditWait", creditWait);  
	    	long insureAmt = siteService.getInsureAmt(loginSite.getSiteId());
	    	long insurePointAmt = siteService.getInsurePointAmt(loginSite.getSiteId());	
	    	model.put("insureAmt", insureAmt);	  
	    	model.put("insurePointAmt", insurePointAmt);	

		  return "admin/apiAuth"; 
		  
	  }
	  	
		@GetMapping({"/apiPlay"})
	  	public String apiPlay( HttpServletRequest request, ModelMap model, @ModelAttribute("searchVO") SiteSearch search) throws Exception {
		  Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
	    	Site loginSite = (Site)authentication.getDetails();
	    	model.put("loginSite", loginSite);
	    	
	    
	    	model.put("loginSite", loginSite);
	    	long siteCredit = siteService.getSiteCredit(loginSite.getSiteId());
	    	long underSiteCredit = siteService.getUnderSiteCredit(loginSite.getSiteId());
	    	model.put("underSiteCredit", underSiteCredit);	
	    	model.put("siteCredit", siteCredit);
	    	long sitePoint = siteService.getSitePoint(loginSite.getSiteId());
	    	model.put("sitePoint", sitePoint);	
	    	HashMap creditWait = siteService.getCreditWait(loginSite.getSiteIdx());
	    	model.put("creditWait", creditWait);  
	    	long insureAmt = siteService.getInsureAmt(loginSite.getSiteId());
	    	long insurePointAmt = siteService.getInsurePointAmt(loginSite.getSiteId());	
	    	model.put("insureAmt", insureAmt);	  
	    	model.put("insurePointAmt", insurePointAmt);	

		  return "admin/apiPlay"; 
		  
	  }
	  	
}
