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

import java.util.Collection;

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

import com.gagaframework.web.parameter.GagaMap;
import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbCouponService;
import com.style24.batch.biz.service.TsbGiftcardService;
import com.style24.batch.support.env.TsbConstants;
import com.style24.core.biz.service.TscKakaotalkService;
import com.style24.persistence.domain.Coupon;
import com.style24.persistence.domain.GiftCard;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class TsbExpectCouponJob  extends TsbAbstractJob<Collection<Coupon>, GagaMap, GagaMap>{
	
	@Autowired
	TsbCouponService couponService;
	
	@Autowired
	TscKakaotalkService kakaoService;
	
	private int succCnt = 0;
	private int failCnt = 0;
	@Override
	public Collection<Coupon> read() throws Exception {
		Coupon coupon = new Coupon();
		return couponService.getSendCouponExpectList(coupon);
	}
	@Override
	public GagaMap process(Collection<Coupon> readItem) throws Exception {
		for (Coupon coupon : readItem) {
			try {
				kakaoService.sendCouponExpectNotify(coupon, coupon.getCustNo());
				succCnt++;
			} catch (Exception e) {
				failCnt++;
				log.error(e.getMessage());
			}
		}
		return null;
	}
	@Override
	public GagaMap write(GagaMap convertedItem) throws Exception {
		return null;
	}
	@Override
	public void notify(GagaMap resultItem) throws Exception {
		super.printResult(succCnt, failCnt);
	}

	
}
