package com.style24.scm.biz.web;

import javax.servlet.http.HttpServletResponse;

import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.parameter.GagaMapList;
import com.style24.persistence.domain.SweetTracker;
import com.style24.scm.biz.service.TssDeliveryService;
import com.style24.scm.support.controller.TssBaseController;
import com.google.gson.JsonObject;

import lombok.extern.slf4j.Slf4j;

/**
 * 배송 Controller
 *
 * @author moon
 * @since 2021. 04. 13
 */
@Controller
@RequestMapping("/delivery")
@Slf4j
public class TssDeliveryController extends TssBaseController {


	@Autowired
	private TssDeliveryService deliveryService;

	/**
	 * 스윗트래커 
	 *
	 * @param String
	 * @return  
	 * @author moon
	 * @since 2021. 04. 13
	 */
	@PostMapping(value = "/sweettracker/response" )
	@ResponseBody
	public String sweetTrackerResponse(SweetTracker  sweetTracker) throws Exception {
		
		deliveryService.saveTemp("들어옴");
		
		String msg = "";
//		Enumeration  enums = request.getParameterNames();
//		while (enums.hasMoreElements()) {
//			String name = (String) enums.nextElement();
//			log.info("name: "+name);
//			msg = msg+ name+": "+request.getParameter(name)+" ";
//		}
//		
//		deliveryService.saveTemp(msg);
//		
//		String fid  = request.getParameter("fid");
//		String courier_code  = request.getParameter("courier_code");
//		String invoice_no  = request.getParameter("invoice_no");
//		String level  = request.getParameter("level");
//		String time_trans  = request.getParameter("time_trans");
//		String time_sweet  = request.getParameter("time_sweet");
//		String where  = request.getParameter("where");
//		String telno_office  = request.getParameter("telno_office");
//		String telno_man  = request.getParameter("telno_man");
//		String details  = request.getParameter("details");
//		String recv_addr  = request.getParameter("recv_addr");
//		String recv_name  = request.getParameter("recv_name");
//		String send_name  = request.getParameter("send_name");
//		String man  = request.getParameter("man");
//		String estmate  = request.getParameter("estmate");
//		
//		String msg2 = "fid: "+fid+" courier_code:"+courier_code+" invoice_no:"+invoice_no+" level:"+level+" time_trans:"+time_trans;
//		
//		deliveryService.saveTemp(msg2);
//		
//		
//		
//		SweetTracker  sweetTracker = new SweetTracker();
//		sweetTracker.setFid(request.getParameter("fid"));
//		sweetTracker.setCourier_code(request.getParameter("courier_code"));
//		sweetTracker.setInvoice_no(request.getParameter("invoice_no"));
//		sweetTracker.setLevel(Integer.parseInt(request.getParameter("level")));
//		sweetTracker.setTime_trans(request.getParameter("time_trans"));
//		sweetTracker.setTime_sweet(request.getParameter("time_sweet"));
//		sweetTracker.setWhere(request.getParameter("where"));
//		sweetTracker.setTelno_office(request.getParameter("telno_office"));
//		sweetTracker.setTelno_man(request.getParameter("telno_man"));
//		sweetTracker.setDetails(request.getParameter("details"));
//		sweetTracker.setRecv_addr(request.getParameter("recv_addr"));
//		sweetTracker.setRecv_name(request.getParameter("recv_name"));
//		sweetTracker.setSend_name(request.getParameter("send_name"));
//		sweetTracker.setMan(request.getParameter("man"));
//		sweetTracker.setEstmate(request.getParameter("estmate"));
//		
		
		deliveryService.saveTemp(sweetTracker.toString());
		
		JsonObject rtn = new JsonObject();
		
		
		try {
			deliveryService.saveDelvStat(sweetTracker);
			
			rtn.addProperty("code", true); 
			rtn.addProperty("message", "success"); 
		} catch(Exception e) {
			rtn.addProperty("code", false); 
			rtn.addProperty("message", "fail - invalid fid"); 
		}
		
		return rtn.toString();
		//response.getWriter().append(rtn+"");
	}	
}
