package com.style24.batch.biz.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

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 lombok.extern.slf4j.Slf4j;

/**
 * 전시 Task
 *
 * @author bin2107
 * @since 2021. 3. 15
 */
@Component
@Slf4j
public class TsbDisplayTask {

	@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
	 */
	@Scheduled(cron = "${cron.display.category.refresh}")
	@Async
	public void cate4SrchRefreshJob() throws Exception {
		cate4SrchJob.runById("cron.display.category.refresh");
	}

	/**
	 * 카테고리별 재고 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.display.category.stock.create}")
	@Async
	public void categoryStockCreateJob() throws Exception {
		cateStockJob.runById("cron.display.category.stock.create");
	}

//	/**
//	 * 카테고리별 검색 필터 생성
//	 * @throws Exception
//	 */
//	@Scheduled(cron = "${cron.display.category.filter.create}")
//	@Async
//	public void categoryFilterCreateJob() throws Exception {
//		cateFilterJob.runById("cron.display.category.filter.create");
//	}

	/**
	 * 최근등록된 상품 100개 생성
	 * @throws Exception
	 */
	@Scheduled(cron = "${cron.display.recently.reg.goods.create}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void recentlyRegGoodsCreateJob() throws Exception {
		recentlyRegGoodsJob.runById("cron.display.recently.reg.goods.create");
	}

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