package com.prime.sony.ecommerce.jobs;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.AutodataCheckServiceException;
import com.prime.sony.ecommerce.service.AutoDataCheckService;

//@Component
@Configuration
public class AutoDataCheckServiceJob {

	private static final Logger log = LoggerFactory.getLogger(AutoDataCheckServiceJob.class);

	
	@Autowired
	private AutoDataCheckService autoDataCheckService;
	
	

	@Scheduled(cron = "#{@getCronValueForAutoDataChecks}") 
	public void loadProductsForAutoDataChecks() throws Exception {
		  
		  log.info("==>AutoDataCheckServiceJob.loadProductsForAutoDataChecks()"); 
		  try {
			  autoDataCheckService.loadProductsForAutoDataChecks(); 
		 } catch (Exception e) {
		  log.error("==> Exception at AutoDataCheckServiceJob.loadProductsForAutoDataChecks()",e)
		  ;
		  
		  throw new AutodataCheckServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==AutoDataCheckServiceJob.loadProductsForAutoDataChecks()"); 
	}
	
	@Scheduled(cron = "#{@getCronValueForAutoDataChecks}") 
	public void loadOrdersForAutoDataChecks() throws Exception {
		  
		  log.info("==>AutoDataCheckServiceJob.loadOrdersForAutoDataChecks()"); 
		  try {
			  autoDataCheckService.loadOrdersForAutoDataChecks(); 
		 } catch (Exception e) {
		  log.error("==> Exception at AutoDataCheckServiceJob.loadOrdersForAutoDataChecks()",e)
		  ;
		  
		  throw new AutodataCheckServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==AutoDataCheckServiceJob.loadOrdersForAutoDataChecks()"); 
	}
	
	@Scheduled(cron = "#{@getCronValueForAutoDataChecks}") 
	public void loadCustomersForAutoDataChecks() throws Exception {
		  
		  log.info("==>AutoDataCheckServiceJob.loadCustomersForAutoDataChecks()"); 
		  try {
			  autoDataCheckService.loadCustomersForAutoDataChecks(); 
		 } catch (Exception e) {
		  log.error("==> Exception at AutoDataCheckServiceJob.loadCustomersForAutoDataChecks()",e)
		  ;
		  
		  throw new AutodataCheckServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==AutoDataCheckServiceJob.loadCustomersForAutoDataChecks()"); 
	}
	
	@Scheduled(cron = "#{@getCronValueForAutoDataChecks}") 
	public void loadGlobalDataProcess() throws Exception {
		  
		  log.info("==>AutoDataCheckServiceJob.loadGlobalDataProcess()"); 
		  try {
			  autoDataCheckService.loadGlobalDataProcess(); 
		 } catch (Exception e) {
		  log.error("==> Exception at AutoDataCheckServiceJob.loadGlobalDataProcess()",e)
		  ;
		  
		  throw new AutodataCheckServiceException(e.getMessage(), e.getCause(), null); 
		  }
		  log.info("<==AutoDataCheckServiceJob.loadGlobalDataProcess()"); 
	}
		 
	 
}
