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

import { suppliersController } 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(suppliersController.meta));
router.get("/template", asyncHandler(suppliersController.downloadTemplate));
router.get("/", asyncHandler(suppliersController.list));
router.get("/aged-balance", asyncHandler(suppliersController.getAgedBalance));
router.get("/schedule", asyncHandler(suppliersController.getSchedule));
router.post(
  "/import",
  upload.single("file"),
  asyncHandler(suppliersController.importItems),
);
router.post("/", asyncHandler(suppliersController.create));
router.get("/:id/statement", asyncHandler(suppliersController.getStatement));
router.get("/:id", asyncHandler(suppliersController.getById));
router.put("/:id", asyncHandler(suppliersController.update));
router.delete("/:id", asyncHandler(suppliersController.remove));

export default router;
