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

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

const AuthController = require("../controllers/AuthController");
// const WebCronController = require("../controllers/ShopperrDS/WebCronController");  
const AdminController = require("../controllers/Admin/AdminController");
const OrderController = require("../controllers/Admin/OrderController");
//_______________________________ Start Amz SP-API List Orders management_______________________________
// router.route("/marketplace/login").post(catchErrors(AuthController.Login));

//Admin Routes
router.route("/adminProfile:admin_id").get(AdminController.AdminProfile);
router.route("/adminAccount").patch(AdminController.AdminAccountUpdate);
router.route("/getSubAdmin").get(AdminController.getSubAdmin);
router.route("/adminOrders").get(AdminController.OrderList);
router.route("/adminPaymentSupplier").get(AdminController.adminPaymentSupplier);
router.route("/getTransaction").get(AdminController.getTransaction);
router.route("/addwarehouse").post(AdminController.adminAddwarehouse);
// router.route("/ticketDetail").post(AdminController.orderTicketDetail);
router.route("/viewwarehouses").get(WarehousepaginatedResults(WareHouse),AdminController.viewwarehouses);
router.route("/deleteWare/:id").delete(AdminController.deleteWare);
router.route("/:id/dispute").post(AdminController.adminOrderDisputeReply);      
router.route("/:id/closeTicket").post(AdminController.adminOrdercloseTicket);
router.route("/refund/:id").post(AdminController.adminOrderRefund);

router.route("/supplierFullDetails").get(AdminController.supplierFullDetails);
router.route("/transactionDetail").post(AdminController.adminTransactionDetail);
router.route("/getProductsAdmin").get(AdminController.GetProducts);
router.route("/getItem/:code").get(AdminController.GetSingleProduct);
router.route("/getSelectedCategory/:id").get(AdminController.getSelectedCategory);
router.route("/selectedProductsofapi").post(AdminController.Productsofapi);
router.route("/categoryList").get(AdminController.CategoryList);
// router.route("/orderReply/:userId").post(AdminController.OrderReply);
router.route("/supplierList").get(AdminController.SupplierList);
router.route("/getUploadUpdateProductCsv").get(AdminController.GetUploadUpdateProductCsv);
router.route("/resellerByName").post(AdminController.adminResellerByName);
router.route("/getUploadProductCsv").get(AdminController.GetUploadProductCsv);
router.route("/downloadProductCsv/:supplier_id").post(AdminController.DownloadProductCsv);
router.route("/uploadProductCsv").post(AdminController.UploadProductCsv);
router.route("/downloadAllOrderCsv").get(AdminController.DownloadAllOrderCsv);
router.route("/order/:id").get(AdminController.SingleOrder);
router.route("/order/:id/message").get(AdminController.OrderIdmessages);
router.route("/getProductPrice").get(AdminController.GetProductPrice);
router.route("/findBySku").get(AdminController.GetProductFindBySku);
router.route("/suppliernewData").get(AdminController.AdminsupplierNewData);         
router.route("/supplierById").get(AdminController.AdminsupplierById);
router.route("/supplierDel/:id").delete(AdminController.AdminsupplierDel);
router.route("/supplierProfile/:id").get(AdminController.AdminsupplierProfile);
router.route("/settingsUpdate").post(AdminController.supplierSettingUpdate);
router.route("/signUp").post(AdminController.AddSupplierProfile); 
router.route("/signUpMerchant").post(AdminController.AddMerchantProfile); 
router.route('/getLogisticUsers').get(LogisticpaginatedResults(AdminUser),AdminController.getLogisticUsers)
router.route("/addLogisticUser").post(AdminController.AddLogisticUser);  
router.route("/viewwarehouse").get(AdminController.LogisticViewWarehouse);  
router.route("/getSelectedLogisticUser/:id").get(AdminController.LogisticGetSelectedLogisticUser);  
router.route("/updateLogisticUser").put(AdminController.updateLogisticUser);  
router.route("/deleteLogisticUser/:id").delete(AdminController.deleteLogisticUser)  
router.route("/autoMargin").patch(AdminController.autoMargin)  
router.route("/totalCategoryMargin").get(AdminController.totalCategoryMargin)  
router.route("/customMerchantDetail").get(AdminController.customMerchantDetail)  
router.route("/userDetails").get(AdminController.usersList)  
router.route("/getBrowseNode").get(AdminController.GetBrowseNodes)
router.route("/updateProduct").post(AdminController.UpdateProduct)
router.route("/orderPriority").post(AdminController.OrderPriority)
router.route("/getPriorityList").get(AdminController.OrderPriorityList)
router.route("/currentStock").post(AdminController.currentStockImport)
 

router.route("/totalCategory").get(AdminController.TotalCategory);
router.route("/subscribedByShopperr").get(AdminController.SubscribeByShopperr);
router.route("/productUpdate").patch(AdminController.productUpdate)
router.route("/markprocess/:processto/:orderid").get(OrderController.markProcess)

router.route("/updateUserType").post(AdminController.updateUserType)
router.route("/updateAddress").post(AdminController.UpdateAddress)
router.route("/getSelectedCategory/:id").get(AdminController.getSelectedCategory)
 router.route("/addCategory").post(AdminController.AddCategory)     
 router.route("/updateCategory").post(AdminController.AddUpdateCategory)   
 router.route("/categoryDel/:id").delete(AdminController.categoryDel)   
  
// var DS_CRON_TAB = process.env.DS_CRON_TAB;
// if (DS_CRON_TAB == 1) {        
//     // cron.schedule('0 */4 * * * *', function () { 
//     cron.schedule('0 */4 * * * *', function () { 
//         WebCronController.SubscribeProductCron();
//         WebCronController.AmazonSubscribeProductCron();
//         WebCronController.bulkUploadOrdersCron();
//         WebCronController.bulkUploadProducts();
           
//     });
// }
module.exports = router;
