package com.style24.batch.biz.task;

import com.style24.batch.biz.job.order.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 *
 * 주문 Task
 * @author xodud1202
 * @since 2021. 05. 03
 */
@Component
@Slf4j
public class TsbOrderTask {

	@Autowired
	private TsbCartExpirationJob cartExpirationJob;

	@Autowired
	private TsbOrderDepositExpirationJob orderDepositExpirationJob;

	@Autowired
	private TsbOrderGiftExpirationJob orderGiftExpirationJob;

	@Autowired
	private TsbCartUnpurchasePushJob cartUnpurchasePushJob;

	@Autowired
	private TsbCartAddCouponPushJob cartAddCouponPushJob;

	@Autowired
	private TsbWishAddCouponPushJob wishAddCouponPushJob;

	@Autowired
	private TsbOrderDepositWaitingNotifyJob orderDepositWaitingNotifyJob;

	/**
	 * 장바구니 30일 초과 만료 데이터 삭제
	 *
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 05. 03
	 */
	@Scheduled(cron = "${cron.order.cart.deadline.expire}")
	// @Scheduled(fixedDelay = 3500000)
	@Async
	public void cartDeadlineExpireJob() throws Exception {
		cartExpirationJob.runById("cron.order.cart.deadline.expire");
	}

	/**
	 * 무통장입금 입금 기한 만료 데이터 취소
	 *
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 05. 03
	 */
	@Scheduled(cron = "${cron.order.deposit.deadline.expire}")
	@Async
	public void depositDeadlineExpireJob() throws Exception {
		orderDepositExpirationJob.runById("cron.order.deposit.deadline.expire");
	}

	/**
	 * 선물하기 배송지 등록 기간 만료 주문 취소
	 *
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 05. 03
	 */
	@Scheduled(cron = "${cron.order.gift.deadline.expire}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void giftDeadlineExpireJob() throws Exception {
		orderGiftExpirationJob.runById("cron.order.gift.deadline.expire");
	}

	/**
	 * 장바구니 미구매 확인(삭제 10일 전) 푸시 송부
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 07. 09
	 */
	@Scheduled(cron = "${cron.order.cart.unpurchase.push}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void cartUnpurchasePushJob() throws Exception {
		cartUnpurchasePushJob.runById("cron.order.cart.unpurchase.push");
	}

	/**
	 * 장바구니 혜택 추가 푸시
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 07. 09
	 */
	@Scheduled(cron = "${cron.order.cart.benefit.push}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void cartBenefitPushJob() throws Exception {
		cartAddCouponPushJob.runById("cron.order.cart.benefit.push");
	}

	/**
	 * 위시리스트 혜택 추가 푸시
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 07. 09
	 */
	@Scheduled(cron = "${cron.order.wish.benefit.push}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void wishlistBenefitPushJob() throws Exception {
		wishAddCouponPushJob.runById("cron.order.wish.benefit.push");
	}

	/**
	 * 무통장입금 입금 대기 알림
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 07. 13
	 */
	@Scheduled(cron = "${cron.order.deposit.waiting.notify}")
	//@Scheduled(fixedDelay = 3500000)
	@Async
	public void orderDepositWaitingNotify() throws Exception {
		orderDepositWaitingNotifyJob.runById("cron.order.deposit.waiting.notify");
	}
}
