const express = require("express");
var app = express();
var bodyParser = require('body-parser');
app.use(bodyParser.json({ limit: '100mb' }));
app.use(bodyParser.urlencoded({ limit: '500mb', extended: true, parameterLimit: 100000 }));
const { catchErrors } = require("../handlers/errorHandlers");
const authenticateUserByToken = require("../apps/middlewares/authenticateUserByToken");

const router = express.Router();
var cron = require('node-cron');

const AuthController = require("../controllers/AuthController");

// const SupplierController = require("../controllers/ShopperrDS/SupplierController");
// const MerchantController = require("../controllers/ShopperrDS/MerchantController");
const WebCronController = require("../controllers/ShopperrDS/WebCronController");
const ShopifyController = require("../controllers/ShopperrDS/ShopifyController");
const WmsCronController = require("../controllers/Wms/WmsCronController");
const BillingController = require("../controllers/BillingController");
const LMStrackingController = require("../controllers/LMStrackingController");
const ReportController = require("../controllers/ReportController");
const SolrCronController = require("../controllers/SolrCronController");


var WEB_CRON_TAB = process.env.WEB_CRON_TAB;
if (WEB_CRON_TAB == 1) {
    // cron.schedule('0 */4 * * * *', function () { 
    cron.schedule('* * * * * *', function () { 
        WebCronController.SubscribeProductCron();
        WebCronController.AmazonSubscribeProductCron();
        // WebCronController.bulkUploadOrdersCron();
        WebCronController.bulkUploadProducts();
    });

    cron.schedule('*/15 * * * * ', function () { 
        // console.log("Cron job running every 2 minutes");
        // ShopifyController.createProductCrone();
        
    });
    cron.schedule('*/5 * * * * ', function () { 
        SolrCronController.SolrB2bAddProducts();
        
    });

}

var WMS_CRON_TAB = process.env.WMS_CRON_TAB;
if (WMS_CRON_TAB == 1) {
    // cron.schedule('0 */4 * * * *', function () { 
    cron.schedule('* * * * * *', function () { 
       // WmsCronController.UploadWmsOrders();
    });

    cron.schedule('* * * * * *', function () { 
        WebCronController.InwardCron();
        WebCronController.ReturnCron();
    });
    
     //cron.schedule('0 9 * * *', function () {
     /*cron.schedule('0 8 * * *', function () {
         WmsCronController.InOffshelf();
     });*/

    cron.schedule('0 8 * * *', function () {
    // cron.schedule('11 16 * * *', function () {
        ReportController.DailySalesReport();
    });

    // cron.schedule('0 1 * * *', function () { 
    cron.schedule('0 14 * * *', function () { 
        // console.log(33333)
        BillingController.exportExcelNewAction();
    });
}

var LMS_CRON_TAB = process.env.LMS_CRON_TAB;
if (LMS_CRON_TAB == 1) {
    cron.schedule('0 0 */23 * * *', function () { 
        LMStrackingController.getTrackings();
    });

    
}


module.exports = router;
