import multer from "multer";
import { Router } from "express";

import { entriesController } from "../controllers/entriesController.js";
import { asyncHandler } from "../utils/asyncHandler.js";

const router = Router();
const upload = multer({
  storage: multer.memoryStorage(),
  limits: {
    fileSize: 8 * 1024 * 1024,
  },
});

router.get("/", asyncHandler(entriesController.list));
router.post("/", asyncHandler(entriesController.create));
router.post(
  "/import",
  upload.single("file"),
  asyncHandler(entriesController.importEntries),
);
router.get("/:id", asyncHandler(entriesController.getById));
router.put("/:id", asyncHandler(entriesController.update));
router.post("/:id/validate", asyncHandler(entriesController.validate));
router.post("/:id/reverse", asyncHandler(entriesController.reverse));
router.delete("/:id", asyncHandler(entriesController.remove));

export default router;
