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

import com.style24.batch.support.env.TsbConstants;
import com.style24.core.biz.checkout.base.ChangedProductOrderInfo;
import com.style24.core.biz.checkout.base.ProductOrderChangeType;
import com.style24.batch.biz.job.TsbAbstractJob;
import com.style24.batch.biz.service.TsbNaverPayService;
import com.style24.core.biz.service.TscNaverPayService;
import com.style24.persistence.domain.Order;
import com.style24.persistence.domain.OrderChange;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 네이버페이 배송준비중 데이터 송신
 *
 * @author xodud1202
 * @since 2021. 05. 27
 */
@Component
@Slf4j
public class TsbNaverPaySendReadyDeliveryJob extends TsbAbstractJob<Collection<Order>, Collection<Order>, Order> {
	@Autowired
	private TsbNaverPayService naverPayService;
	@Autowired
	private TscNaverPayService coreNaverPayService;

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

	@Override
	public Collection<Order> read() throws Exception {
		// 배송중 테스트
		/*Collection<Order> testList = new ArrayList<>();
		Order tmp = new Order(); tmp.setOrdDtlNo(7259);
		Order tmp2 = new Order(); tmp2.setOrdDtlNo(7197);
		testList.add(tmp);testList.add(tmp2);
		coreNaverPayService.sendNaverPayDeliveryStartOrder(testList, "SHIPPING", TsbConstants.REG_NO);*/

		// 교환 WMS 예외(불량, 품절) 반품처리 > 완료까지.
		/*Order order = new Order(); order.setOrdDtlNo(7254);
		OrderChange change = new OrderChange(); change.setOrdChgSq(1064);
		coreNaverPayService.sendNaverPayRejectExchange(change, TsbConstants.REG_NO);
		coreNaverPayService.sendNaverPaySoldoutReturnReq(order, TsbConstants.REG_NO);
		coreNaverPayService.sendNaverPayReturnComplete(change, TsbConstants.REG_NO);*/

		/*Order order = new Order(); order.setOrdDtlNo(7298);
		coreNaverPayService.sendNaverPaySoldoutCancel(order, TsbConstants.REG_NO);*/

		log.info("<<<< 배송준비중 송신 시작 >>>>");
		Order time = coreNaverPayService.setInitData();
		return coreNaverPayService.getReadyDeliveryList(time); // 변경 상품주문 조회;
	}

	@Override
	public Collection<Order> process(Collection<Order> readyDeliveryList) throws Exception {
		return readyDeliveryList;
	}

	@Override
	public Order write(Collection<Order> readyDeliveryList) throws Exception {
		Order result = new Order();
		if (readyDeliveryList != null) {
			// 배송 준비중 데이터 네이버로 송신
			result = coreNaverPayService.sendNaverPayReadyDeliveryOrder(readyDeliveryList, TsbConstants.REG_NO);
		}

		log.info("<<<< 배송준비중 송신 종료 >>>>");
		return result;
	}

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