const multer = require("multer");

// Store in memory so we can save to data/<email>.pdf in controller
const storage = multer.memoryStorage();

const fileFilter = (req, file, cb) => {
  if (file.mimetype === "application/pdf") {
    cb(null, true);
  } else {
    cb(new Error("Only PDF files are allowed."), false);
  }
};

const uploadPortfolio = multer({
  storage,
  fileFilter,
  limits: { fileSize: 10 * 1024 * 1024 }, // 10 MB
}).single("portfolio");

// Multi-file upload handler for portfolio, marriage certificate, and age proof
const uploadFiles = multer({
  storage,
  fileFilter,
  limits: { fileSize: 10 * 1024 * 1024 }, // 10 MB per file
}).fields([
  { name: "portfolio", maxCount: 1 },
  { name: "marriage_certificate", maxCount: 1 },
  { name: "age_proof", maxCount: 1 },
]);

module.exports = { uploadPortfolio, uploadFiles };
