const express = require("express");
const router = express.Router();
const multer = require("multer");
const validateFirebaseIdTokenMiddleware = require("../middleware/validateFirebaseIdTokenMiddleware");
const withUserGraphQLClientMiddleware = require("../middleware/withUserGraphQLClientMiddleware");
const { handleBillOcr, handleBillOcrStatus } = require("../ai/bill-ocr/bill-ocr");
const { handleBillAiFeedback } = require("../ai/bill-ai-feedback");

// Configure multer for form data parsing (memory storage)
const upload = multer({
	limits: {
		fileSize: 5 * 1024 * 1024 // 5MB
	}
});

router.use(validateFirebaseIdTokenMiddleware);
router.use(withUserGraphQLClientMiddleware);

router.post("/bill-ocr", upload.single('billScan'), handleBillOcr);
router.get("/bill-ocr/status/:textractJobId", handleBillOcrStatus);

router.post("/bill-feedback", upload.single("billPdf"), handleBillAiFeedback);

module.exports = router;
