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

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

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

router.get("/meta", asyncHandler(clientsController.meta));
router.get("/template", asyncHandler(clientsController.downloadTemplate));
router.get("/", asyncHandler(clientsController.list));
router.get("/aged-balance", asyncHandler(clientsController.getAgedBalance));
router.get("/schedule", asyncHandler(clientsController.getSchedule));
router.post(
  "/import",
  upload.single("file"),
  asyncHandler(clientsController.importItems),
);
router.post("/", asyncHandler(clientsController.create));
router.get("/:id/statement", asyncHandler(clientsController.getStatement));
router.get("/:id", asyncHandler(clientsController.getById));
router.put("/:id", asyncHandler(clientsController.update));
router.delete("/:id", asyncHandler(clientsController.remove));

export default router;
