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

import java.util.Collection;

import com.gagaframework.web.parameter.GagaMap;
import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbCustomerService;
import com.style24.core.support.env.TscConstants;
import com.style24.persistence.domain.Customer;
import com.style24.persistence.domain.CustomerSearch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 마케팅 정보 수신동의 내역 안내 발송
 *
 * @author jsshin
 * @since 2021.05.06
 */
@Component
@Slf4j
public class TsbMarketingAgreeNoticeJob extends TsbAbstractJob<Collection<Customer>, GagaMap, GagaMap> {

	@Autowired
	private TsbCustomerService customerService;

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

	@Override
	public Collection<Customer> read() throws Exception {
		CustomerSearch customerSearch = new CustomerSearch();
		customerSearch.setSiteCd(TscConstants.Site.STYLE24.value());
		return customerService.getMarketingAgreeNoticeTargetList(customerSearch);
	}

	@Override
	public GagaMap process(Collection<Customer> customerCollection) throws Exception {
		return customerService.sendMarketingAgreeNotice(customerCollection);
	}

	@Override
	public GagaMap write(GagaMap result) throws Exception {
		succCnt = result.getInt("succCnt");
		failCnt = result.getInt("failCnt");
		return result;
	}

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