import express from "express";
import {
  createProduct,
  getAllProductAdmin,
  updateProduct,
  deleteProduct,
  getOneProduct,
  deleteImageFromCloudinary,
  getProductsByCategory,
  getAllProductUser,
  getAllProductsDevicesFirst,
  ChangeProductStatus,
  uploadProducts,
} from "./ProductController.js";

import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";

const router = express.Router();

router
  .route('/products/upload').post( 
    isAuthenticatedUser, 
  authorizeRoles('admin'), 
  uploadProducts
);


router
  .route("/product/create/")
  .post(isAuthenticatedUser, authorizeRoles("admin"), createProduct);
router
  .route("/product/getAll/admin/")
  .get(isAuthenticatedUser, authorizeRoles("admin"), getAllProductAdmin);

//change Product status
router.route("/product/admin/status/:id").patch(ChangeProductStatus);

//get all product user
router.route("/product/getAll/user/").get(getAllProductUser);
router
  .route("/product/getAllProductsDevicesFrist/")
  .get(getAllProductsDevicesFirst);
router.route("/product/getOne/:id").get(getOneProduct);
router
  .route("/product/update/:id")
  .patch(isAuthenticatedUser, authorizeRoles("admin"), updateProduct);
router
  .route("/product/delete/:id")
  .delete(isAuthenticatedUser, authorizeRoles("admin"), deleteProduct);
router
  .route("/product/deleteImage/:public_id")
  .delete(
    isAuthenticatedUser, authorizeRoles("admin"),
    deleteImageFromCloudinary
  );
router.route("/products/category/:categoryName").get(getProductsByCategory);
export default router;
