const { Router } = require("express");
const prisma = require("../prisma");
const { requireAuth, requireRoles } = require("../middleware/auth");

const router = Router();

// Admin approves a user for full access
router.post("/users/:id/approve", requireAuth, requireRoles(["Admin"]), async (req, res, next) => {
  try {
    const id = req.params.id;
    const user = await prisma.user.update({
      where: { id },
      data: { isApproved: true },
      select: { id: true, email: true, fullName: true, username: true, isApproved: true },
    });
    return res.json(user);
  } catch (err) {
    return next(err);
  }
});

module.exports = router;

