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

import {
  bankAccountsController,
  bankMovementsController,
} 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(bankAccountsController.list));
router.get("/template", asyncHandler(bankAccountsController.downloadTemplate));
router.post(
  "/import",
  upload.single("file"),
  asyncHandler(bankAccountsController.importItems),
);
router.post("/", asyncHandler(bankAccountsController.create));
router.get("/:id", asyncHandler(bankAccountsController.getById));
router.put("/:id", asyncHandler(bankAccountsController.update));
router.delete("/:id", asyncHandler(bankAccountsController.remove));
router.get("/:id/movements", asyncHandler(bankMovementsController.list));
router.post("/:id/movements", asyncHandler(bankMovementsController.create));
router.post(
  "/:id/import-statement",
  upload.single("file"),
  asyncHandler(bankMovementsController.importStatement),
);

export default router;
