package com.style24.batch.biz.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.style24.batch.biz.job.marketing.TsbCartExpirationJob;
import com.style24.batch.biz.job.order.TsbOrderDepositExpirationJob;
import com.style24.batch.biz.job.order.TsbOrderGiftExpirationJob;
import com.style24.core.support.controller.TscBaseController;

import lombok.extern.slf4j.Slf4j;

/**
 * 주문 Controller
 * 
 * @author gagamel
 * @since 2021. 5. 24
 */
@Controller
@RequestMapping("/order")
@CrossOrigin(origins = "${domain.admin}")
@Slf4j
public class TsbOrderController extends TscBaseController {

	@Autowired
	private TsbCartExpirationJob cartExpirationJob;

	@Autowired
	private TsbOrderDepositExpirationJob orderDepositExpirationJob;

	@Autowired
	private TsbOrderGiftExpirationJob orderGiftExpirationJob;

	/**
	 * 장바구니 30일 초과 만료 데이터 삭제
	 *
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 05. 03
	 */
	@GetMapping("/cart/deadline/expire")
	@ResponseBody
	public String expireCartDeadline() throws Exception {
		cartExpirationJob.runById("cron.order.cart.deadline.expire");
		return "OK";
	}

	/**
	 * 무통장입금 입금 기한 만료 데이터 취소
	 *
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 05. 03
	 */
	@GetMapping("/deposit/deadline/expire")
	@ResponseBody
	public String expireDepositDeadline() throws Exception {
		orderDepositExpirationJob.runById("cron.order.deposit.deadline.expire");
		return "OK";
	}

	/**
	 * 선물하기 배송지 등록 기간 만료 주문 취소
	 *
	 * @throws Exception - 예외처리
	 * @author xodud1202
	 * @since 2021. 05. 03
	 */
	@GetMapping("/gift/deadline/expire")
	@ResponseBody
	public String expireGiftDeadline() throws Exception {
		orderGiftExpirationJob.runById("cron.order.gift.deadline.expire");
		return "OK";
	}

}
