const express = require("express")
const router = express.Router()
const Enrollment = require("../../models/Enrollment")
const requireAuth = require("../../middleware/requireAuth")

router.get("/access/:courseId", requireAuth, async (req, res) => {
  try {
    const enrollment = await Enrollment.findOne({
      user: req.user._id,
      course: req.params.courseId,
      status: "active"
    })

    res.json({ hasAccess: !!enrollment })
  } catch (error) {
    res.status(500).json({ message: "Access check failed" })
  }
})

module.exports = router
