package com.style24.admin.biz.web;

import com.gagaframework.web.parameter.GagaMap;
import com.gagaframework.web.util.GagaDateUtil;
import com.style24.admin.biz.service.*;
import com.style24.admin.support.controller.TsaBaseController;
import com.style24.admin.support.security.session.TsaSession;
import com.style24.core.support.message.TscMessageByLocale;
import com.style24.persistence.TsaPageRequest;
import com.style24.persistence.domain.FreeGoodsPromotion;
import com.style24.persistence.domain.SupplyCompany;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * 마케팅 Controller
 * @author xodud1202
 * @since 2020. 12.16
 */
@Controller
@RequestMapping("/marketing")
@Slf4j
public class TsaMarketingController extends TsaBaseController {

	@Autowired
	private TscMessageByLocale message;

	@Autowired
	private Environment env;

	@Autowired
	private TsaMarketingService marketingService;

	@Autowired
	private TsaBusinessService businessService;

	@Autowired
	private TsaRendererService rendererService;

	@Autowired
	private TsaCommonService commonService;

	@Autowired
	private TsaSystemService systemService;

	/* xodud1202 진행 */
	/**
	 * 사은품 프로모션 관리 화면
	 * @author xodud1202
	 * @since 2020. 12. 16
	 */
	@GetMapping("/freeGoods/promotion/form")
	public ModelAndView freeGoodsPromotionForm() {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("marketing/FreeGoodsPromotionForm");
		return mav;
	}

	/**
	 * 사은품 프로모션 목록 조회
	 * @author xodud1202
	 * @since 2020. 10. 17
	 */
	@PostMapping("/freeGoodsPromotion/list")
	@ResponseBody
	public GagaMap getFreeGoodsPromotionList(@RequestBody FreeGoodsPromotion param) {
		GagaMap result = new GagaMap();

		List<FreeGoodsPromotion> marketingList = (ArrayList<FreeGoodsPromotion>) marketingService.getFreeGoodsPromotionList(param);

		param.setRegNo(TsaSession.getInfo().getUserNo()); // 엑셀조회시 로그인 사용자의 엑셀 상품조회시 사용
		param.setPageable(new TsaPageRequest(param.getPageNo() - 1, param.getPageSize()));
		param.getPageable().setTotalCount(marketingList.size());

		result.set("pageing", param);
		result.set("freeGoodsList", marketingList);

		return result;
	}


	/**
	 * 세트상품구성 화면
	 *
	 * @param
	 * @return
	 * @author eskim
	 * @since 2020. 05. 26
	 */
	@ResponseBody
	@GetMapping("/freeGoodsRegiPopup/form")
	public ModelAndView freeGoodsRegiForm(FreeGoodsPromotion param) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("param", param);
		mav.setViewName("marketing/FreeGoodsPromotionRegiForm");
		return mav;
	}


	/* // xodud1202 진행 */

	/* JSM 진행 */

	/* // JSM 진행 */
}