var express = require('express');
const multer = require('multer')
const upload = multer({ dest: 'uploads/' })
var router = express.Router();

const adminController = require('../controller/adminController');
/* GET Routes */
router.get('/', adminController.validateAdmin, adminController.dashboard);
router.get('/login', adminController.login);
router.get('/forgotpassword', adminController.forgotpassword);
router.get('/allOrders', adminController.validateAdmin, adminController.allOrders);
router.get('/allUsers', adminController.validateAdmin, adminController.allUsers);
router.get('/allProducts', adminController.validateAdmin, adminController.allProducts);
router.get('/addProduct', adminController.validateAdmin, adminController.addProduct);
router.get('/logout', adminController.logout);

// POST Routes
router.post('/validate_login', adminController.validateInput('login'), adminController.validate_login);
router.post('/updateOrderStatus', upload.none(), adminController.login);
router.post('/updateUserStatus', upload.none(), adminController.login);
router.post('/updateProductStatus', upload.none(), adminController.updateProductStatus);
router.post('/updateUser', upload.none(), adminController.login);
router.post('/updateProduct', adminController.login);
router.post('/updateStatus', upload.none(), adminController.updateStatus);

const cpUpload = upload.fields([{ name: 'thumbnail', maxCount: 1 }, { name: 'multi_img[]', maxCount: 8 }])

router.post('/insertProduct', cpUpload, adminController.insertProduct);

module.exports = router;
