package com.prime.sony.ecommerce.jobs;

import java.sql.Connection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;

import com.prime.sony.ecommerce.exceptions.DeleteRequestServiceException;
import com.prime.sony.ecommerce.exceptions.TaskStatusServiceException;
import com.prime.sony.ecommerce.service.TaskStatusService;

//@Component
@Configuration
public class TaskStatusServiceJob {

	private static final Logger log = LoggerFactory.getLogger(TaskStatusServiceJob.class);

	// @Override
	// public void execute(JobExecutionContext context) throws JobExecutionException
	// {
	// // TODO Auto-generated method stub
	// System.out.println("Test Job");
	// }

//	@Autowired
//	JobLauncher jobLauncher;
	
//	@Autowired
//	private Connection connection;

//	@Autowired
//	Job job;
	
	@Autowired
	private TaskStatusService taskStatusService;
	
	/*
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadProductStageToSpTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info("==>TaskStatusServiceJob.loadProductStageToSpTaskHistoryScheduler()"
	 * ); try { taskStatusService.loadProductStageToSpTaskHistory(); } catch
	 * (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadProductStageToSpTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info("<==TaskStatusServiceJob.loadProductStageToSpTaskHistoryScheduler()"
	 * ); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadCustomerStageToSpTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadCustomerStageToSpTaskHistoryScheduler()"); try {
	 * taskStatusService.loadCustomerStageToSpTaskHistory(); } catch (Exception e) {
	 * log.
	 * error("==> Exception at TaskStatusServiceJob.loadCustomerStageToSpTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadCustomerStageToSpTaskHistoryScheduler()"); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadOrderStageToSpTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info("==>TaskStatusServiceJob.loadOrderStageToSpTaskHistoryScheduler()");
	 * try { taskStatusService.loadOrderStageToSpTaskHistory(); } catch (Exception
	 * e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadOrderStageToSpTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info("<==TaskStatusServiceJob.loadOrderStageToSpTaskHistoryScheduler()");
	 * }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadProductSpToEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadProductSpToEcommerceTaskHistoryScheduler()");
	 * try { taskStatusService.loadProductSpToEcommerceTaskHistory(); } catch
	 * (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadProductSpToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadProductSpToEcommerceTaskHistoryScheduler()"); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadCustomerSpToEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadCustomerSpToEcommerceTaskHistoryScheduler()");
	 * try { taskStatusService.loadCustomerSpToEcommerceTaskHistory(); } catch
	 * (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadCustomerSpToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadCustomerSpToEcommerceTaskHistoryScheduler()"); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadOrderSpToEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadOrderSpToEcommerceTaskHistoryScheduler()"); try
	 * { taskStatusService.loadOrderSpToEcommerceTaskHistory(); } catch (Exception
	 * e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadOrderSpToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadOrderSpToEcommerceTaskHistoryScheduler()"); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadCustomerLookupEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadCustomerLookupEcommerceTaskHistoryScheduler()");
	 * try { taskStatusService.loadCustomerLookupEcommerceTaskHistory(); } catch
	 * (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadCustomerLookupEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadCustomerLookupEcommerceTaskHistoryScheduler()");
	 * }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadCustomerTotalSpentEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadCustomerTotalSpentEcommerceTaskHistoryScheduler()"
	 * ); try { taskStatusService.loadCustomerTotalSpentEcommerceTaskHistory(); }
	 * catch (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadCustomerTotalSpentEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadCustomerTotalSpentEcommerceTaskHistoryScheduler()"
	 * ); }
	 */
	 
	
	/*
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadProductForShopifyToEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadProductForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); try { taskStatusService.loadProductForShopifyToEcommerceTaskHistory(); }
	 * catch (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadProductForShopifyToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadProductForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadCustomerForShopifyToEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadCustomerForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); try { taskStatusService.loadCustomerForShopifyToEcommerceTaskHistory(); }
	 * catch (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadCustomerForShopifyToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadCustomerForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadOrderForShopifyToEcommerceTaskHistoryScheduler() throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadOrderForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); try { taskStatusService.loadOrderForShopifyToEcommerceTaskHistory(); }
	 * catch (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadOrderForShopifyToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadOrderForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadCustomerLookupForShopifyToEcommerceTaskHistoryScheduler() throws
	 * Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadCustomerLookupForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); try {
	 * taskStatusService.loadCustomerLookupForShopifyToEcommerceTaskHistory(); }
	 * catch (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadCustomerLookupForShopifyToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadCustomerLookupForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadCustomerTotalSpentForShopifyEcommerceTaskHistoryScheduler() throws
	 * Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadCustomerTotalSpentForShopifyEcommerceTaskHistoryScheduler()"
	 * ); try {
	 * taskStatusService.loadCustomerTotalSpentForShopifyEcommerceTaskHistory(); }
	 * catch (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadCustomerTotalSpentForShopifyEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadCustomerTotalSpentForShopifyEcommerceTaskHistoryScheduler()"
	 * ); }
	 * 
	 * @Scheduled(cron="#{@getCronValue}") public void
	 * loadOrderTotalQuantityUpdateForShopifyToEcommerceTaskHistoryScheduler()
	 * throws Exception {
	 * 
	 * log.info(
	 * "==>TaskStatusServiceJob.loadOrderTotalQuantityUpdateForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); try { taskStatusService.
	 * loadOrderTotalQuantityUpdateForShopifyToEcommerceTaskHistory(); } catch
	 * (Exception e) { log.
	 * error("==> Exception at TaskStatusServiceJob.loadOrderTotalQuantityUpdateForShopifyToEcommerceTaskHistoryScheduler()"
	 * ,e);
	 * 
	 * throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	 * log.info(
	 * "<==TaskStatusServiceJob.loadOrderTotalQuantityUpdateForShopifyToEcommerceTaskHistoryScheduler()"
	 * ); }
	 */
	
	@Scheduled(cron="#{@getCronValue}")
	public void loadProductLogHistory() throws Exception {
		
		log.info("==>TaskStatusServiceJob.loadProductLogHistory()");
		try {
			taskStatusService.loadProductLogHistory();
		} catch (Exception e) {
			log.error("==> Exception at TaskStatusServiceJob.loadProductLogHistory()",e);
			
			throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null);
		}
		log.info("<==TaskStatusServiceJob.loadProductLogHistory()");
	}
	
	
	@Scheduled(cron = "#{@getCronValue}")
	public void loadOrderLogHistory() throws Exception {
	  
	  log.info("==>TaskStatusServiceJob.loadOrderLogHistory()"); try {
	  taskStatusService.loadOrderLogHistory(); } catch (Exception e) {
	  log.error("==> Exception at TaskStatusServiceJob.loadOrderLogHistory()",e);
	  
	  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	  log.info("<==TaskStatusServiceJob.loadOrderLogHistory()"); 
	 }
	  
	@Scheduled(cron = "#{@getCronValue}")
	public void loadCustomerLogHistory() throws Exception {
	  
	  log.info("==>TaskStatusServiceJob.loadCustomerLogHistory()"); try {
	  taskStatusService.loadCustomerLogHistory(); } catch (Exception e) {
	  log.error("==> Exception at TaskStatusServiceJob.loadCustomerLogHistory()",e);
	  
	  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	  log.info("<==TaskStatusServiceJob.loadCustomerLogHistory()"); 
	 }
	
	@Scheduled(cron = "#{@getCronValue}") 
	public void loadShopifyProductDataFeedingProcess() throws Exception {
		  
		  log.info("==>TaskStatusServiceJob.loadShopifyProductDataFeedingProcess()"); 
		  try {
			  taskStatusService.loadShopifyProductDataFeedingProcess(); 
		 } catch (Exception e) {
		  log.error("==> Exception at TaskStatusServiceJob.loadShopifyProductDataFeedingProcess()",e)
		  ;
		  
		  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==TaskStatusServiceJob.loadShopifyProductDataFeedingProcess()"); 
	}
	

	@Scheduled(cron = "#{@getCronValue}") 
	public void loadShopifyCustomerDataFeedingProcess() throws Exception {
		  
		  log.info("==>TaskStatusServiceJob.loadShopifyCustomerDataFeedingProcess()"); 
		  try {
			  taskStatusService.loadShopifyCustomerDataFeedingProcess(); 
		 } catch (Exception e) {
		  log.error("==> Exception at TaskStatusServiceJob.loadShopifyCustomerDataFeedingProcess()",e)
		  ;
		  
		  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==TaskStatusServiceJob.loadShopifyCustomerDataFeedingProcess()"); 
	}
	
	@Scheduled(cron = "#{@getCronValue}") 
	public void loadShopifyOrderDataFeedingProcess() throws Exception {
		  
		  log.info("==>TaskStatusServiceJob.loadShopifyOrderDataFeedingProcess()"); 
		  try {
			  taskStatusService.loadShopifyOrderDataFeedingProcess(); 
		 } catch (Exception e) {
		  log.error("==> Exception at TaskStatusServiceJob.loadShopifyOrderDataFeedingProcess()",e)
		  ;
		  
		  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==TaskStatusServiceJob.loadShopifyOrderDataFeedingProcess()"); 
	}
	
	@Scheduled(cron = "#{@getCronValue}") 
	public void loadShopifyCustomerTotalSpentDataFeedingProcess() throws Exception {
		  
		  log.info("==>TaskStatusServiceJob.loadShopifyCustomerTotalSpentDataFeedingProcess()"); 
		  try {
			  taskStatusService.loadShopifyCustomerTotalSpentDataFeedingProcess(); 
		 } catch (Exception e) {
		  log.error("==> Exception at TaskStatusServiceJob.loadShopifyCustomerTotalSpentDataFeedingProcess()",e)
		  ;
		  
		  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==TaskStatusServiceJob.loadShopifyCustomerTotalSpentDataFeedingProcess()"); 
	}
	
	@Scheduled(cron = "#{@getCronValue}") 
	public void loadShopifyTotalQuantityDataFeedingProcess() throws Exception {
		  
		  log.info("==>TaskStatusServiceJob.loadShopifyTotalQuantityDataFeedingProcess()"); 
		  try {
			  taskStatusService.loadShopifyTotalQuantityDataFeedingProcess(); 
		 } catch (Exception e) {
		  log.error("==> Exception at TaskStatusServiceJob.loadShopifyTotalQuantityDataFeedingProcess()",e)
		  ;
		  
		  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==TaskStatusServiceJob.loadShopifyTotalQuantityDataFeedingProcess()"); 
	}
	
	@Scheduled(cron = "#{@getCronValue}")
	public void loadShopifyMasterDataLogHistory() throws Exception {
	  
	  log.info("==>TaskStatusServiceJob.loadShopifyMasterDataLogHistory()"); try {
	  taskStatusService.loadShopifyMasterDataLogHistory(); } catch (Exception e) {
	  log.error("==> Exception at TaskStatusServiceJob.loadShopifyMasterDataLogHistory()",e);
	  
	  throw new TaskStatusServiceException(e.getMessage(), e.getCause(), null); }
	  log.info("<==TaskStatusServiceJob.loadShopifyMasterDataLogHistory()"); 
	 }
	 
}
