package com.style24.front.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.RequestBody;
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.front.biz.service.TsfDeliveryService;
import com.style24.front.support.controller.TsfBaseController;
import com.google.gson.JsonObject;

import lombok.extern.slf4j.Slf4j;

/**
 * 배송 Controller
 *
 * @author moon
 * @since 2021. 04. 25
 */
@Controller
@RequestMapping("/delivery")
@Slf4j
public class TsfDeliveryController extends TsfBaseController {


	@Autowired
	private TsfDeliveryService deliveryService;

	/**
	 * 스윗트래커 
	 *
	 * @param String
	 * @return  
	 * @author moon
	 * @since 2021. 04. 13
	 */
	@RequestMapping(value = "/sweettracker/response" , method=RequestMethod.POST, consumes="application/json")
	@ResponseBody
	public String sweetTrackerResponse(@RequestBody SweetTracker  sweetTracker) throws Exception {

		log.info("sweettracker call");
		log.info("sweetTracker {}"+sweetTracker);
		
		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();
	}	
}
