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.delivery.TsbShopGoodsStockJob;
import com.style24.batch.biz.job.goods.TsbDaumAllEp;
import com.style24.batch.biz.job.goods.TsbDaumReviewEp;
import com.style24.batch.biz.job.goods.TsbDaumSummaryEp;
import com.style24.batch.biz.job.goods.TsbGoodsBenefitJob;
import com.style24.batch.biz.job.goods.TsbGoodsBenefitPriceJob;
import com.style24.batch.biz.job.goods.TsbGoodsPriceJob;
import com.style24.batch.biz.job.goods.TsbGoodsReinboundJob;
import com.style24.batch.biz.job.goods.TsbGoodsRelateScoreJob;
import com.style24.batch.biz.job.goods.TsbGoodsSearchAllJob;
import com.style24.batch.biz.job.goods.TsbGoodsSearchSectionJob;
import com.style24.batch.biz.job.goods.TsbGoodsSnmJob;
import com.style24.batch.biz.job.goods.TsbGoodsSummaryJob;
import com.style24.batch.biz.job.goods.TsbGoodsTnmJob;
import com.style24.batch.biz.job.goods.TsbGoodsVwStockJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsBrandproviderJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsGoodsJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsGoodsStockJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsIncomelotJob;
import com.style24.batch.biz.job.goods.TsbGoodsWmsMeasurementJob;
import com.style24.batch.biz.job.goods.TsbNaverAllEp;
import com.style24.batch.biz.job.goods.TsbNaverSellEp;
import com.style24.batch.biz.job.goods.TsbNaverSummaryEp;
import com.style24.batch.biz.job.social.TsbSocialGoodsJob;
import com.style24.core.support.controller.TscBaseController;

import lombok.extern.slf4j.Slf4j;

/**
 * 상품 Controller
 * 
 * @author gagamel
 * @since 2021. 5. 24
 */
@Controller
@RequestMapping("/goods")
@CrossOrigin(origins = "${domain.admin}")
@Slf4j
public class TsbGoodsController extends TscBaseController {

	@Autowired
	private TsbGoodsTnmJob goodsTnmJob;

	@Autowired
	private TsbGoodsPriceJob goodsPriceJob;

	@Autowired
	private TsbGoodsSnmJob goodsSnmJob;

	@Autowired
	private TsbGoodsBenefitPriceJob goodsBenefitPriceJob;

	@Autowired
	private TsbGoodsRelateScoreJob goodsRelateScoreJob;

	@Autowired
	private TsbGoodsSummaryJob goodsSummaryJob;

	@Autowired
	private TsbGoodsWmsMeasurementJob goodsWmsMeasurementJob;

	@Autowired
	private TsbGoodsWmsIncomelotJob goodsWmsIncomelotJob;

	@Autowired
	private TsbGoodsWmsBrandproviderJob goodsWmsBrandproviderJob;

	@Autowired
	private TsbGoodsWmsGoodsJob goodsWmsGoodsJob;

	@Autowired
	private TsbGoodsWmsGoodsStockJob goodsWmsGoodsStockJob;

	@Autowired
	private TsbNaverAllEp naverAllEp;

	@Autowired
	private TsbNaverSummaryEp naverSummaryEp;

	@Autowired
	private TsbNaverSellEp naverSellEp;

	@Autowired
	private TsbDaumAllEp daumAllEp;

	@Autowired
	private TsbDaumSummaryEp daumSummaryEp;

	@Autowired
	private TsbDaumReviewEp daumReviewEp;

	@Autowired
	private TsbGoodsBenefitJob goodsBenefitJob;

	@Autowired
	private TsbShopGoodsStockJob tsbShopGoodsStockJob;

	@Autowired
	private TsbGoodsSearchAllJob goodsSearchAllJob;

	@Autowired
	private TsbGoodsSearchSectionJob goodsSearchSectionJob;

	@Autowired
	private TsbSocialGoodsJob socialGoodsJob;

	@Autowired
	private TsbGoodsReinboundJob goodsReinboundJob;

	@Autowired
	private TsbGoodsVwStockJob goodVwStockJob;

	/**
	 * 상품 타이틀예약 적용 주기 : 시간배치 - 매시 1분 (소셜과 시간 중복)
	 *
	 * @throws Exception
	 */
	@GetMapping("/reserve/titlename/apply")
	@ResponseBody
	public String applyReserveTitlename() throws Exception {
		goodsTnmJob.runById("cron.goods.reserve.titlename.apply");
		return "OK";
	}

	/**
	 * 상품 가격예약 적용 주기 : 시간배치 - 매시 1분 (소셜과 시간 중복)
	 *
	 * @throws Exception
	 */
	@GetMapping("/reserve/price/apply")
	@ResponseBody
	public String applyReservePrice() throws Exception {
		goodsPriceJob.runById("cron.goods.reserve.price.apply");
		return "OK";
	}

	/**
	 * 상품 검색어 적용 주기 : 시간배치 - 매시 5분
	 *
	 * @throws Exception
	 */
	@GetMapping("/keyword/create")
	@ResponseBody
	public String createKeyword() throws Exception {
		goodsSnmJob.runById("cron.goods.keyword.create");
		return "OK";
	}

	/**
	 * 상품 즉시할인가 생성 : 시간배치 - 매시 2분
	 *
	 * @throws Exception
	 * @author eskim
	 * @since 2020. 12. 02.
	 */
	@GetMapping("/benefit/price/create")
	@ResponseBody
	public String createBenefitPrice() throws Exception {
		goodsBenefitPriceJob.runById("cron.goods.benefit.price.create");
		return "OK";
	}

//	/**
//	 * 연관상품보기 스코어링 주기 : 일배치 - 매일 2시
//	 *
//	 * @throws Exception
//	 */
//	@GetMapping("/relgoods/scoring")
//	@ResponseBody
//	public String createRelationGoodsScoring() throws Exception {
//		goodsRelateScoreJob.runById("cron.goods.relgoods.scoring");
//		return "OK";
//	}

	/**
	 * 전시상품 통계정보 주기 : 일배치 - 매일 1시 5분
	 *
	 * @throws Exception
	 */
	@GetMapping("/summary/create")
	@ResponseBody
	public String createSummary() throws Exception {
		goodsSummaryJob.run("cron.goods.summary.create");
		return "OK";
	}

	/**
	 * WMS 실측사이즈 연동 적용 주기 : 일배치 - 03시
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/measurement/receive")
	@ResponseBody
	public String receiveWmsMeasurement() throws Exception {
		goodsWmsMeasurementJob.runById("cron.goods.wms.measurement.receive");
		return "OK";
	}

	/**
	 * WMS 입고상품 연동 적용 주기 : 일배치 - 03시 10분
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/incomelot/receive")
	@ResponseBody
	public String receiveWmsIncomelot() throws Exception {
		goodsWmsIncomelotJob.runById("cron.goods.wms.incomelot.receive");
		return "OK";
	}

	/**
	 * WMS 업체/브랜드 송신 적용 주기 : 일배치 - 03시 12분
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/brandprovider/send")
	@ResponseBody
	public String sendWmsBrandprovider() throws Exception {
		goodsWmsBrandproviderJob.runById("cron.goods.wms.brandprovider.send");
		return "OK";
	}

	/**
	 * WMS 상품정보 송신 적용 주기 : 일배치 - 03시 15분
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/goods/send")
	@ResponseBody
	public String sendWmsGoods() throws Exception {
		goodsWmsGoodsJob.runById("cron.goods.wms.goods.send");
		return "OK";
	}

	/**
	 * WMS 상품 재고 수신 적용 주기 : 시간배치 - 01분
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/stock/receive")
	@ResponseBody
	public String receiveWmsStock() throws Exception {
		goodsWmsGoodsStockJob.runById("cron.goods.wms.stock.receive");
		return "OK";
	}

	/**
	 * 네이버 전체EP 생성
	 * @throws Exception
	 */
	@GetMapping("/ep/naver/all/goods/create")
	@ResponseBody
	public String createNaverAllEpJob() throws Exception {
		naverAllEp.runById("cron.goods.ep.naver.all.goods.create");
		return "OK";
	}

	/**
	 * 네이버 요약EP 생성
	 * @throws Exception
	 */
	@GetMapping("/ep/naver/summary/goods/create")
	@ResponseBody
	public String createNaverSummaryEpJob() throws Exception {
		naverSummaryEp.runById("cron.goods.ep.naver.summary.goods.create");
		return "OK";
	}

	/**
	 * 네이버 판매지수EP 생성
	 * @throws Exception
	 */
	@GetMapping("/ep/naver/sell/create")
	@ResponseBody
	public String createNaverSellEpJob() throws Exception {
		naverSellEp.runById("cron.goods.ep.naver.sell.create");
		return "OK";
	}

	/**
	 * 다음 전체EP 생성
	 * @throws Exception
	 */
	@GetMapping("/ep/daum/all/goods/create")
	@ResponseBody
	public String createDaumAllEpJob() throws Exception {
		daumAllEp.runById("cron.goods.ep.daum.all.goods.create");
		return "OK";
	}

	/**
	 * 다음 요약EP 생성
	 * @throws Exception
	 */
	@GetMapping("/ep/daum/summary/goods/create")
	@ResponseBody
	public String createDaumSummaryEpJob() throws Exception {
		daumSummaryEp.runById("cron.goods.ep.daum.summary.goods.create");
		return "OK";
	}

	/**
	 * 다음 상품평EP 생성
	 * @throws Exception
	 */
	@GetMapping("/ep/daum/review/create")
	@ResponseBody
	public String createDaumReviewEpJob() throws Exception {
		daumReviewEp.runById("cron.goods.ep.daum.review.create");
		return "OK";
	}

	/**
	 * 상품혜택(쿠폰할인, 무료배송, 사은품, 신상) 생성
	 * @throws Exception
	 */
	@GetMapping("/benefit/create")
	@ResponseBody
	public String createBenefit() throws Exception {
		goodsBenefitJob.runById("cron.goods.benefit.create");
		return "OK";
	}

	/**
	 * 매장상품재고 수신
	 *
	 * @throws Exception
	 */
	@GetMapping("/shop/stock/receive")
	@ResponseBody
	public String receiveShopGoodsStock() throws Exception {
		tsbShopGoodsStockJob.run("cron.goods.shop.stock.receive");
		return "OK";
	}

	/**
	 * 소셜 상품 적용 : 시간배치 - 매시 00분
	 *
	 * @throws Exception
	 */
	@GetMapping("/social/price/apply")
	@ResponseBody
	public String applySocialPrice() throws Exception {
		socialGoodsJob.runById("cron.goods.social.price.apply");
		return "OK";
	}

	/**
	 * 검색상품-전체색인 : 일배치
	 *
	 * @throws Exception
	 */
	@GetMapping("/search/all/create")
	@ResponseBody
	public String createGoodsSearchAll() throws Exception {
		goodsSearchAllJob.runById("cron.goods.search.all.create");
		return "OK";
	}

	/**
	 * 검색상품-부분색인 : 시간배치
	 *
	 * @throws Exception
	 */
	@GetMapping("/search/section/create")
	@ResponseBody
	public String createGoodsSearchSection() throws Exception {
		goodsSearchSectionJob.runById("cron.goods.search.section.create");
		return "OK";
	}

	/**
	 * 재입고 알림톡  : 시간배치
	 *
	 * @throws Exception
	 */
	@GetMapping("/reinbound/notify")
	@ResponseBody
	public String notifyGoodsReinbound() throws Exception {
		goodsReinboundJob.runById("cron.goods.reinbound.notify");
		return "OK";
	}

	/**
	 * 상품 VW_STOCK 생성
	 *
	 * @throws Exception
	 */
	@GetMapping("/vwstock/create")
	@ResponseBody
	public String createGoodsVwStockJob() throws Exception {
		goodVwStockJob.runById("cron.goods.vwstock.create");
		return "OK";
	}

}
