const express = require("express");
const { body } = require("express-validator");
const validation = require("../../../../middlewares/routeValidation");
const isAuth = require("../../../../middlewares/authorization");
const jsonParser = require("../../../../helpers/jsonParser");
const pagination = require("../../../../middlewares/pagination");

const {
  getAllSellerProducts,
  getSellerProductById,
  createSellerProduct,
  updateProductPhoto,
  updateSellerProduct,
  deleteSellerProduct,
} = require("../../../../controllers/seller/products");
const { SELLER_PRODUCTS_MODULE } = require("../../../../helpers/common");
const checkPermissionMiddleware = require("../../../../middlewares/permission");

const router = express.Router();

router.use(pagination);
router.get(
  "/",
  isAuth,
  checkPermissionMiddleware(SELLER_PRODUCTS_MODULE, "view"),
  getAllSellerProducts
);
router.get(
  "/:product_id",
  isAuth,
  checkPermissionMiddleware(SELLER_PRODUCTS_MODULE, "view"),
  getSellerProductById
);
router.post(
  "/",
  isAuth,
  jsonParser,
  checkPermissionMiddleware(SELLER_PRODUCTS_MODULE, "add"),
  createSellerProduct
);
router.patch(
  "/:product_id/:photo_id",
  isAuth,
  checkPermissionMiddleware(SELLER_PRODUCTS_MODULE, "edit"),
  updateProductPhoto
);
router.put(
  "/:product_id",
  isAuth,
  checkPermissionMiddleware(SELLER_PRODUCTS_MODULE, "edit"),
  updateSellerProduct
);
router.delete(
  "/:product_id",
  isAuth,
  checkPermissionMiddleware(SELLER_PRODUCTS_MODULE, "delete"),
  deleteSellerProduct
);

module.exports = router;
