package com.style24.batch.biz.web;

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 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.delivery.TsbCjWithdrawInvoiceJob;
import com.style24.batch.biz.job.delivery.TsbCjWithdrawInvoiceStatJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawExcRcvJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawExcRsltJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawRequestJob;
import com.style24.batch.biz.job.delivery.TsbWithdrawRsltJob;

import lombok.extern.slf4j.Slf4j;

/**
 * 회수 Controller
 * @author moon
 * @since 2021. 06. 22
 */
@Controller
@RequestMapping("/withdraw")
@CrossOrigin(origins = "${domain.admin}")
@Slf4j
public class TsbWithdrawController {

	@Autowired
	private TsbWithdrawExcRcvJob withdrawExcRcvJob;

	@Autowired
	private TsbWithdrawExcRsltJob withdrawExcRsltJob;

	@Autowired
	private TsbWithdrawRsltJob withdrawRsltJob;

	@Autowired
	private TsbWithdrawRequestJob tsbWithdrawRequestJob;

	@Autowired
	private TsbCjWithdrawInvoiceJob tsbCjWithdrawInvoiceJob;

	@Autowired
	private TsbCjWithdrawInvoiceStatJob tsbCjWithdrawInvoiceStatJob;



	/**
	 * WMS 회수요청
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/request")
	@ResponseBody
	public String shotDeliveryZoneRefreshJob() throws Exception {
		tsbWithdrawRequestJob.run("cron.withdraw.wms.request");
		return "OK";
	}
	

	/**
	 * WMS 회수입고예외 수신
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/ingoing/exception/receive")
	@ResponseBody
	public String withdrawWmsIngoingExceptionReceiveJob() throws Exception {
		withdrawExcRcvJob.run("cron.withdraw.wms.ingoing.exception.receive");
		return "OK";
	}

	/**
	 * WMS 회수입고예외결과 송신
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/ingoing/exception/result/receive")
	@ResponseBody
	public String withdrawWmsIngoingExceptionResultReceiveJob() throws Exception {
		withdrawExcRsltJob.run("cron.withdraw.wms.ingoing.exception.result.receive");
		return "OK";
	}

	/**
	 * WMS 회수입고결과 수신
	 *
	 * @throws Exception
	 */
	@GetMapping("/wms/ingoing/result/receive")
	@ResponseBody
	public String withdrawWmsIngoingResultReceiveJob() throws Exception {
		withdrawRsltJob.run("cron.withdraw.wms.ingoing.result.receive");
		return "OK";
	}

	/**
	 * CJ 회수송장번호 수신
	 *
	 * @throws Exception
	 */
	@GetMapping("/cj/invoice/receive")
	@ResponseBody
	public String withdrawCjInvoiceReceiveJob() throws Exception {
		tsbCjWithdrawInvoiceJob.run("cron.withdraw.cj.invoice.receive");
		return "OK";
	}

	/**
	 * CJ 회수상태 수신
	 *
	 * @throws Exception
	 */
	@GetMapping("/cj/status/receive")
	@ResponseBody
	public String withdrawCjStatusJob() throws Exception {
		tsbCjWithdrawInvoiceStatJob.run("cron.withdraw.cj.status.receive");
		return "OK";
	}

}
