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

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

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

router.get("/", asyncHandler(accountsController.list));
router.get("/auxiliaries", asyncHandler(accountsController.listAuxiliaries));
router.post("/", asyncHandler(accountsController.create));
router.post(
  "/import",
  upload.single("file"),
  asyncHandler(accountsController.importAccounts),
);
router.get("/:id", asyncHandler(accountsController.getById));
router.put("/:id", asyncHandler(accountsController.update));
router.delete("/:id", asyncHandler(accountsController.remove));

export default router;
