const express = require("express");
const productControllers = require("../controllers/productControllers.js");
const auth = require("../auth.js");

// Router
const router = express.Router();

const {verify, verifyAdmin, verifyNonAdmin} = auth;


// Route for creating a product
router.post(`/create`, verify, verifyAdmin, productControllers.createProduct);


// Route for retrieving all products
router.get(`/all`, verify, verifyAdmin, productControllers.getAllProducts);

// Route for retrieving all active products
router.get(`/`, productControllers.getAllActiveProducts);

// Route for searching products
router.get(`/search`, productControllers.searchProducts);

// Route for updating products
router.put(`/:productId`, verify, verifyAdmin, productControllers.updateProduct);

// Route for archiving a product
router.put(`/:productId/archive`, verify, verifyAdmin, productControllers.archiveProduct);

// Route for activate a product
router.put(`/:productId/activate`, verify, verifyAdmin, productControllers.activateProduct);

// Route to create an order || check-out
router.post(`/create-order`, verify, verifyNonAdmin, productControllers.createOrder);


// My Cart

router.post('/add-to-cart', verify, verifyNonAdmin, productControllers.addProductToCart);
router.put('/update-quantity', productControllers.updateProductQuantity);
router.delete('/remove/:productId', verify, verifyNonAdmin, productControllers.removeProductFromCart);
router.get('/view-my-cart', verify, verifyNonAdmin, productControllers.getCartDetails);


module.exports = router;