package com.madeu.controller.api.doctalk;

import com.madeu.init.ManagerDraftAction;
import com.madeu.service.api.doctalk.DocTalkService;
import com.madeu.common.service.LogHistoryService;
import com.madeu.util.HttpUtil;
import com.madeu.util.RequestLogUtil;
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.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;


@Slf4j
@Controller
public class DocTalkController extends ManagerDraftAction{

	@Autowired
	private DocTalkService docTalkService;

	@Autowired
	private LogHistoryService logHistoryService;

	/**
	 * <b>예약 생성</b>
	 * 네이버 예약 발생시, 닥톡에서 API 호출
	 * 닥톡에서 네이버 예약 요청 파라미터를 전달해줌
	 *
	 *
	 * 페이지 처리 없음 
	 * request: 
	 * response : msgCode, msgDesc		
	 * 
	 * @param request
	 * @param response 
	 * @return
	 */
	@RequestMapping(value="/add-booking",method=RequestMethod.POST,produces="application/json;charset=utf8")
	@ResponseBody
	public HashMap<String, Object> insertReserveNaver(HttpServletRequest request, HttpServletResponse response) {
			
		log.debug("DocTalkController insertReserveNaver START");

		HashMap<String, Object> paramMap = HttpUtil.getParameterMap(request);
		HashMap<String, Object> map = new HashMap<String, Object>();

		StringBuffer errorMsg = new StringBuffer();

		try{
			map = docTalkService.insertReserveNaver(paramMap);
		}catch(Exception e){
			e.printStackTrace();
			errorMsg.append(e);
		}finally {

			logHistoryService.save("예약 생성", "DocTalk", paramMap, map, String.valueOf(errorMsg));
		}
	
		log.debug("DocTalkController insertReserveNaver END");
		
		return map;
	}
}
