package com.style24.batch.biz.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.style24.batch.biz.job.display.TsbCategory4SrchJob;
import com.style24.batch.biz.job.display.TsbCategoryFilterJob;
import com.style24.batch.biz.job.display.TsbCategoryStockJob;
import com.style24.batch.biz.job.display.TsbMainContentsGoodsJob;
import com.style24.batch.biz.job.display.TsbRecentlyRegGoodsJob;
import com.style24.core.support.controller.TscBaseController;

import lombok.extern.slf4j.Slf4j;

/**
 * 전시 Controller
 *
 * @author gagamel
 * @since 2021. 5. 24
 */
@Controller
@RequestMapping("/display")
@CrossOrigin(origins = "${domain.admin}")
@Slf4j
public class TsbDisplayController extends TscBaseController {

	@Autowired
	private TsbCategory4SrchJob cate4SrchJob;

	@Autowired
	private TsbCategoryStockJob cateStockJob;

	@Autowired
	private TsbCategoryFilterJob cateFilterJob;

	@Autowired
	private TsbRecentlyRegGoodsJob recentlyRegGoodsJob;

	@Autowired
	private TsbMainContentsGoodsJob mainContentsGoodsJob;

	/**
	 * 카테고리4SRCH 생성 - 매시 10분마다 0초 기준
	 * @throws Exception
	 */
	@GetMapping("/category/refresh")
	@ResponseBody
	public String refreshCate4Srch() throws Exception {
		cate4SrchJob.runById("cron.display.category.refresh");
		return "OK";
	}

	/**
	 * 카테고리별 재고 생성
	 * @throws Exception
	 */
	@GetMapping("/category/stock/create")
	@ResponseBody
	public String createCategoryStock() throws Exception {
		cateStockJob.runById("cron.display.category.stock.create");
		return "OK";
	}

//	/**
//	 * 카테고리별 검색 필터 생성
//	 * @throws Exception
//	 */
//	@GetMapping("/category/filter/create")
//	@ResponseBody
//	public String createCategoryFilter() throws Exception {
//		cateFilterJob.runById("cron.display.category.filter.create");
//		return "OK";
//	}

	/**
	 * 최근등록된 상품 100개 생성
	 * @throws Exception
	 */
	@GetMapping("/recently/reg/goods/create")
	@ResponseBody
	public String createRecentlyRegGoods() throws Exception {
		recentlyRegGoodsJob.runById("cron.display.recently.reg.goods.create");
		return "OK";
	}

	/**
	 * 몰 메인 컨텐츠 상품생성
	 * @throws Exception
	 */
	@GetMapping("/main/contents/goods/create")
	@ResponseBody
	public String createMainContentsGoods() throws Exception {
		mainContentsGoodsJob.runById("cron.display.main.contents.goods.create");
		return "OK";
	}
}
