const express = require('express');
const router = express.Router();

const { uploadProduct } = require('../config/cloudinaryUpload');

const { asyncHandler, authUser, authAdmin } = require('../auth/checkAuth');

const controllerProduct = require('../controller/product.controller');

router.post('/create', authAdmin, uploadProduct.array('images', 10), asyncHandler(controllerProduct.createProduct));
router.put('/update/:id', authAdmin, uploadProduct.array('images', 10), asyncHandler(controllerProduct.updateProduct));
router.delete('/delete/:id', authAdmin, asyncHandler(controllerProduct.deleteProduct));
router.get('/list', asyncHandler(controllerProduct.getAllProduct));

router.get('/category/:categoryId', asyncHandler(controllerProduct.getProductByCategory));
router.get('/:id', asyncHandler(controllerProduct.getProductById));

module.exports = router;
