package com.madeu.controller.web.webpopbillpoint;

import com.madeu.constants.Constants;
import com.madeu.common.service.LogHistoryService;
import com.madeu.service.web.webpopbillpoint.WebPopbillPointService;
import com.madeu.util.HttpUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Slf4j
@Controller
public class WebPopbillPointController{

	@Autowired
	private WebPopbillPointService webPopbillPointService;

	@Autowired
	private LogHistoryService logHistoryService;

	/**
	 * 잔여 포인트 조회
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webpopbillpoint/selectPopbillPoint.do")
	@ResponseBody
	public HashMap<String, Object> selectPopbillPoint(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
			
		log.debug("WebPopbillPointController selectPopbillPoint START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		StringBuffer errorMsg = new StringBuffer();
		
		try{
			paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
			paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
			paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
			map = webPopbillPointService.selectPopbillPoint(paramMap);
		}catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}

						logHistoryService.save("잔여 포인트 조회", "잔여 포인트 조회", paramMap, map, String.valueOf(errorMsg));
		}
		
		log.debug("WebPopbillPointController selectPopbillPoint END");
		
		return map;
	}
	
	/**
	 * 포인트 충전 이동
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/webpopbillpoint/chargePopbillPointIntro.do")
	@ResponseBody
	public HashMap<String, Object> chargePopbillPointIntro(HttpSession session,HttpServletRequest request, HttpServletResponse response) {
			
		log.debug("WebPopbillPointController chargePopbillPoint START");
		
		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();
		
		StringBuffer errorMsg = new StringBuffer();
		
		try{
			paramMap.put("loginMemberId", String.valueOf(session.getAttribute("loginMemberId")));
			paramMap.put("regId", String.valueOf(session.getAttribute("loginMemberId")));
			paramMap.put("modId", String.valueOf(session.getAttribute("loginMemberId")));
			map = webPopbillPointService.chargePopbillPointIntro(paramMap);
		}catch (Exception e) {
			e.printStackTrace();
			errorMsg.append(e);
		}finally {
			if(Constants.OK == map.get("msgCode")) {

			}
			else{
				map.put("msgCode", Constants.FAIL);
				map.put("success", false);
				if(null == map.get("msgDesc") || ("").equals(map.get("msgDesc"))) {
					map.put("msgDesc","정상적으로 수행되지 않았습니다. 관리자에게 문의하시기 바랍니다.");
				}
			}

						logHistoryService.save("포인트 충전 이동", "포인트 충전 이동", paramMap, map, String.valueOf(errorMsg));
		}
		
		log.debug("WebPopbillPointController chargePopbillPointIntro END");
		
		return map;
	}
}
