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.TsbCommonService;
import com.style24.batch.biz.service.TsbWmsGoodsService;
import com.style24.persistence.domain.IfBrand;

import lombok.extern.slf4j.Slf4j;

import com.gagaframework.web.util.GagaDateUtil;

/**
 * WMS 브랜드/업체정보 송신
 *
 * @author eskim
 * @since 2021. 01. 05
 */
@Component
@Slf4j
public class TsbGoodsWmsBrandproviderJob extends TsbAbstractJob<IfBrand, IfBrand, IfBrand> {

	@Autowired
	private TsbWmsGoodsService wmsGoodsService;

	@Autowired
	private TsbCommonService commonService;

	private int succCnt = 0;
	private int failCnt = 0;

	@Override
	public IfBrand read() throws Exception {

		// WMS 동기화 옵션 여부 확인
		String wmsSyncYn = commonService.getWmsSyncYn();
		if ("N".equals(wmsSyncYn)) {
			log.info("WMS 정보 동기화 미실행 {}, 연동여부 : {}", GagaDateUtil.getToday("yyyy-MM-dd HH:mm:ss"), wmsSyncYn);
			return null;
		}
		IfBrand ifBrand = new IfBrand();
		return ifBrand;
	}

	@Override
	public IfBrand process(IfBrand ifBrand) throws Exception {
		return ifBrand;
	}

	@Override
	public IfBrand write(IfBrand ifBrand) throws Exception {

		wmsGoodsService.saveWmsBrandProvider();

		return ifBrand;
	}

	@Override
	public void notify(IfBrand ifBrand) throws Exception {
		super.printResult(succCnt, failCnt);
	}

}