const express = require("express");

const router = express.Router();

const upload = require("../middleware/productUpload");

const {
  createProduct,
  getProducts,
  getProduct,
  updateProduct,
  deleteProduct,
} = require("../controllers/productController");

router.post(
  "/",
  upload.fields([
    {
      name: "product_images",
      maxCount: 20,
    },
    {
      name: "gallery_images",
      maxCount: 50,
    },
    {
      name: "catalog_pdf",
      maxCount: 1,
    },
  ]),
  createProduct,
);
router.put(
  "/:id",
  upload.fields([
    {
      name: "product_images",
      maxCount: 20,
    },
    {
      name: "gallery_images",
      maxCount: 50,
    },
    {
      name: "catalog_pdf",
      maxCount: 1,
    },
  ]),
  updateProduct,
);
router.get("/", getProducts);

router.get("/:id", getProduct);

router.delete("/:id", deleteProduct);

module.exports = router;
