package com.style24.batch.biz.job.goods;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbGoodsService;

import lombok.extern.slf4j.Slf4j;

/**
 * 상품혜택(쿠폰할인, 무료배송, 사은품, 신상) 생성
 *
 * @author gagamel
 * @since 2021. 4. 7
 */
@Component
@Slf4j
public class TsbGoodsBenefitJob extends TsbAbstractJob<String, String, String> {

	@Autowired
	private TsbGoodsService goodsService;

	@Override
	public String read() throws Exception {
		return "OK";
	}

	@Override
	public String process(String result) throws Exception {
		int cnt = goodsService.createTemporaryGoodsBenefit();
		log.info("1.상품혜택임시 생성: 총 {}건", cnt);

		if (cnt > 0) {
			cnt = goodsService.createGoodsBenefit();
			log.info("2.상품혜택 생성: {}건", cnt);
		}

		return result;
	}

	@Override
	public String write(String result) throws Exception {
		return result;
	}

	@Override
	public void notify(String result) throws Exception {
		// Do nothing
	}

}