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

import {
  cashMovementsController,
  cashRegistersController,
} from "../controllers/treasuryController.js";
import { asyncHandler } from "../utils/asyncHandler.js";

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

router.get("/", asyncHandler(cashRegistersController.list));
router.get("/template", asyncHandler(cashRegistersController.downloadTemplate));
router.post(
  "/import",
  upload.single("file"),
  asyncHandler(cashRegistersController.importItems),
);
router.post("/", asyncHandler(cashRegistersController.create));
router.get("/:id", asyncHandler(cashRegistersController.getById));
router.put("/:id", asyncHandler(cashRegistersController.update));
router.delete("/:id", asyncHandler(cashRegistersController.remove));
router.get("/:id/movements", asyncHandler(cashMovementsController.list));
router.post("/:id/movements", asyncHandler(cashMovementsController.create));

export default router;
