function docancelorder(id){
    axios.get(`/shopperrds/cancelorder/${id}`)
    .then(res=> {
        if(res.data.error===0){
            getSingleOrder(id)
        }
        
    })
}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 {
//     authenticateKeyToken,
//     findByPhoneNumber,
//     findByEmailAndPassword,
//     ifAlreadyExists,
//     findById,
//     ifOtpVerified,
//   } = require("../apps/middlewares/mobileAuthenticateUser");


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

const AuthController = require("../controllers/AuthController");
// const ProductController = require("../controllers/ShopperrDS/ProductController");
// const BillController = require("../controllers/ShopperrDS/BillController");
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 SolrController = require("../controllers/ShopperrDS/SolrController");
const ProductController = require("../controllers/ShopperrDS/ProductController");
//_______________________________ Start Amz SP-API List Orders management_______________________________
router.route("/marketplace/login").post(catchErrors(AuthController.Login)); 

// router.route("/subscribeproduct").post(ProductController.Subscribe);
// router.route("/ewallet").post(BillController.Ewallet);
router.route("/supplierList").get(SupplierController.List);
router.route("/leftOrdermerchantShopify:merchantId/:start/:end").get(MerchantController.OrderShopify);
router.route("/merchantDashboardOrder/:merchantId/:start/:end").get(MerchantController.DashboardOrder);
router.route("/merchantTopProducts/:merchantId").get(MerchantController.TopProducts);
// router.route("/merchantDasboardGraph/:merchantId/:start/:end").get(MerchantController.DashboardGraph);
router.route("/merchantTotalRevenue/:merchantId/:start/:end").get(MerchantController.TotalRevenue);
router.route("/getProducts/:merchantId/:start/:end").get(MerchantController.ProductsData);
router.route("/merchantOrderDetail/:merchantId").get(MerchantController.merchantOrderDetail);
router.route("/merchantOrderDetail/:merchantId").get(MerchantController.merchantOrderDetail);
router.route("/merchant/:id").get(MerchantController.merchant);
router.route("/orders").get(MerchantController.OrderList);     
router.route("/order/:id").get(MerchantController.SingleOrder);   
router.route("/downloadOrderCsv").get(MerchantController.DownloadOrderCsv);
router.route("/getCsvByMerchant").post(MerchantController.GetCsvByMerchant);
router.route("/bulkUploadOrder").post(MerchantController.BulkUploadOrder);
router.route("/subscribedProduct").get(MerchantController.SubscribedProduct);
router.route("/subscribeProduct").post(MerchantController.UnSubscribProduct);
router.route("/getSubscribeExcelDataByMerchant/:id").get(MerchantController.SebscribeExcelMerchant);
router.route("/uploadSubscribeProductCsv").post(MerchantController.UploadSubscribeProduct);
router.route("/uploadAmazonCsv").post(MerchantController.UploadAmazonCsv);
router.route("/customers").get(MerchantController.customers);
router.route("/merchantProfile/:userId").get(MerchantController.customersMerchantProfile);
router.route("/settingsUpdateMerchant").post(MerchantController.customersMerchantSettingUpdate);
 


// router.route("/customer/:id").get(MerchantController.customershow);
// router.route("/gst-verify/:id").put(MerchantController.customergst);
router.route("/getMerchant").post(MerchantController.getMerchant);
router.route("/paynow").post(MerchantController.MerchantPaynow);
router.route("/cashfree").post(MerchantController.MerchantCashfree);
router.route("/getPaymentHistory").get(MerchantController.MerchantPaymentHistory);
router.route("/shopdata").get(authenticateUserByToken, MerchantController.StoreData);
router.route("/delete").put(MerchantController.StoreDataUpdate);
router.route("/cancelorder/:id").get(MerchantController.OrderCancel);
router.route("/payInfo").post(MerchantController.GetPayInfo);
router.route("/payConfirm").post(MerchantController.ConfirmPayment);
router.route("/disputeOrder").post(MerchantController.OrderDispute);
router.route("/disputeOrderMessage").post(MerchantController.OrderDisputeMessage);
router.route("/ticketInformation").post(MerchantController.TicketInfo);
router.route("/ticketClose").post(MerchantController.TicketClose);
router.route("/razorPay").post(MerchantController.MerchantRazorPay);
router.route("/verification").post(MerchantController.RazorPayVerification);
router.route("/razorpaysuccess").post(MerchantController.RazorpaySuccess);
router.route("/createProduct").post(ShopifyController.createProduct);
router.route("/createProductCrone").get(ShopifyController.createProductCrone);
router.route("/d2cProductCount").get(ShopifyController.d2cProductCount);
router.route("/updateBalance").post(MerchantController.updateBalance);

// router.route("/allCollections").get(ShopifyController.getCollections);
// router.route("/getAllProductsTemp").get(ShopifyController.getAllProductsTemp);
router.route("/updateProductPrice").get(ShopifyController.updateProductPrice);
router.route("/merchantAddMargin").post(MerchantController.MerchantAddMargin);
router.route("/fulfillmentLeftOrder/:merchantId/:start/:end").get(MerchantController.FulfillmentLeftOrders);
router.route("/shippedOrders/:merchantId/:start/:end").get(MerchantController.ShippedOrders);
router.route("/cancelledOrders/:merchantId/:start/:end").get(MerchantController.CancelledOrders);
 
router.route("/createApi").post(authenticateUserByToken, MerchantController.CreateShopifyApi);
// router.route("/ordersCreate").post(MerchantController.orderCreateShopify);
router.route("/webhookUpdate").post(MerchantController.webhookUpdate);
 
// webhooks route
// router.post("/webhook/customer_create", customerController.customer_create);
router.post("/webhook/orders_create", MerchantController.orderCreateShopify);
// router.post("/webhook/product_update", productController.webhook_update)
router.route("/solr/toprated").post(catchErrors(SolrController.topratedProducts));
router.route("/solr/searchproducts").post(catchErrors(SolrController.searchProducts));
router.route("/solr/getproduct").post(SolrController.getSingleProductByHandle);
router.route("/getproductinfoByPId").post(ProductController.getProductInfobyProductId);
router.route("/addtocart").post(ProductController.addToCart);      
router.route("/checkout").post(ProductController.productCheckout);
router.route("/get-states").get(ProductController.getStates);
router.route("/get-categories").post(ProductController.getCategories);
router.route("/getwebsiteCategories").get(ProductController.websiteCategories);
router.route("/order/payment").get(MerchantController.PaymentOfOrder);
router.route("/user-addresses").post(ProductController.userAddresses);
router.route("/cashfreeNotify").post(ProductController.orderSucess);
router.route("/apply-discountcode").post(ProductController.applyDiscountcode);
router.route("/order-complete").post(ProductController.confirmOrder);
router.route("/orderid").post(ProductController.getOrderId);
router.route("/deductBalance").post(ProductController.deductBalance);
router.route("/cartUpdate").post(ProductController.cartUpdate);

// var DS_CRON_TAB = process.env.DS_CRON_TAB;
// if (DS_CRON_TAB == 1) {
//     cron.schedule('* * * * * *', function () { 
//         WebCronController.SubscribeProductCron();
//         WebCronController.AmazonSubscribeProductCron();
//         // WebCronController.bulkUploadOrdersCron();
//         WebCronController.bulkUploadProducts();
//     });
//     cron.schedule('*/20 * * * * ', function () { 
//         // console.log("Cron job running every 2 minutes");
//         ShopifyController.createProductCrone();        
//     });
// }
module.exports = router;
