const { Router } = require("express");
const { authMiddleware } = require("../middlewares/auth.middleware");
const { authorizeRoles } = require("../middlewares/role.middleware");

const {
  submitFeedback,

  // admin
  getFeedbackStats,
  getFeedbacks,
  getFeedbackById,
  toggleHighlightFeedback,
  replyToFeedback,
  markFeedbackAsRead,

  // user
  getMyFeedbacks,

  // public
  getTestimonials,
} = require("../controllers/feedback.controller");

const feedbackRouter = Router();

/**
 * =========================
 * STUDENT / TEACHER / Accountant
 * =========================
 */

// Submit feedback
feedbackRouter.post(
  "/",
  authMiddleware,
  authorizeRoles("student", "teacher", "accountant"),
  submitFeedback
);

// View own feedbacks
feedbackRouter.get(
  "/me",
  authMiddleware,
  authorizeRoles("student", "teacher", "accountant"),
  getMyFeedbacks
);

/**
 * =========================
 * ADMIN
 * =========================
 */

// Feedback stats cards
feedbackRouter.get(
  "/stats",
  authMiddleware,
  authorizeRoles("admin"),
  getFeedbackStats
);

// Feedback list (filters: all | unread | highlighted)
feedbackRouter.get("/", authMiddleware, authorizeRoles("admin"), getFeedbacks);

// View single feedback (auto mark read)
feedbackRouter.get(
  "/:id",
  authMiddleware,
  authorizeRoles("admin"),
  getFeedbackById
);

// Mark feedback as read
feedbackRouter.patch(
  "/read/:id",
  authMiddleware,
  authorizeRoles("admin"),
  markFeedbackAsRead
);

// Highlight / unhighlight feedback
feedbackRouter.patch(
  "/highlight/:id",
  authMiddleware,
  authorizeRoles("admin"),
  toggleHighlightFeedback
);

// Reply to feedback
feedbackRouter.post(
  "/reply/:id",
  authMiddleware,
  authorizeRoles("admin"),
  replyToFeedback
);

/**
 * =========================
 * PUBLIC (Testimonials)
 * =========================
 */

// Highlighted feedbacks only
feedbackRouter.get("/public/testimonials", getTestimonials);

module.exports = feedbackRouter;
