// backend/routes/payment.routes.js
const { Router } = require("express");
const { authMiddleware } = require("../middlewares/auth.middleware");
const { authorizeRoles } = require("../middlewares/role.middleware");
const upload = require("../middlewares/upload.middleware");
const paymentCtrl = require("../controllers/payment.controller");

const paymentRouter = Router();

// Student creates payment request -> returns QR + txnId
paymentRouter.post("/create", authMiddleware, paymentCtrl.createPaymentRequest);
// Student: payment history
paymentRouter.get(
  "/my-payments",
  authMiddleware,
  authorizeRoles("student"),
  paymentCtrl.getMyPayments
);

// Student uploads proof (multipart)
paymentRouter.post(
  "/upload-proof",
  authMiddleware,
  upload.single("proof"),
  paymentCtrl.uploadPaymentProof
);

// Admin: list pending
paymentRouter.get(
  "/list-payments",
  authMiddleware,
  authorizeRoles("admin", "accountant"),
  paymentCtrl.listPayments
);

// Admin: approve/reject
paymentRouter.patch(
  "/approve/:id",
  authMiddleware,
  authorizeRoles("admin", "accountant"),
  paymentCtrl.approvePayment
);
paymentRouter.patch(
  "/reject/:id",
  authMiddleware,
  authorizeRoles("admin", "accountant"),
  paymentCtrl.rejectPayment
);

paymentRouter.get(
  "/:id",
  authMiddleware,
  authorizeRoles("admin", "accountant"),
  paymentCtrl.getPaymentById
);
module.exports = paymentRouter;
