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

import com.gagaframework.web.parameter.GagaMap;
import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbCustomerService;
import com.style24.batch.support.env.TsbConstants;
import com.style24.core.biz.service.TscEnvsetService;
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;

import java.util.Collection;

/**
 * 1년지난 회원 탈퇴정보 삭제
 *
 * @author jsshin
 * @since 2021.03.08
 */
@Component
@Slf4j
public class TsbSecedeProcessJob extends TsbAbstractJob<Collection<Customer>, GagaMap, GagaMap> {

	@Autowired
	TsbCustomerService customerService;

	@Autowired
	TscEnvsetService coreEnvsetService;

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

	@Override
	public Collection<Customer> read() throws Exception {
		int rejoinRejectDay = coreEnvsetService.getRejoinRejectDays(TscConstants.Site.STYLE24.value());
		CustomerSearch customerSearch = new CustomerSearch();
		customerSearch.setRejoinRejectDay(rejoinRejectDay);
		customerSearch.setRegNo(TsbConstants.REG_NO);
		customerSearch.setUpdNo(TsbConstants.REG_NO);
		customerSearch.setSiteCd(TscConstants.Site.STYLE24.value());
		return customerService.getExpireSecedeCustomerList(customerSearch);
	}

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

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

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