const mongoose = require("mongoose")

const EnrollmentSchema = new mongoose.Schema({
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "User",
    required: true
  },
  course: {
    type: mongoose.Schema.Types.ObjectId,
    ref: "Course",
    required: true
  },
  status: {
    type: String,
    enum: ["active", "revoked"],
    default: "active"
  },
  createdAt: {
    type: Date,
    default: Date.now
  }
})

EnrollmentSchema.index({ user: 1, course: 1 }, { unique: true })

module.exports = mongoose.model("Enrollment", EnrollmentSchema)
