Source: models/eventModel.js

/**
 * @file Defines the Mongoose schema and model for an Event.
 * @module models/eventModel
 * @requires mongoose
 */

const mongoose = require("mongoose");

/**
 * @typedef Event
 * @property {string} title - The title of the event (required).
 * @property {string} description - A detailed description of the event (required).
 * @property {Date} date - The date and time of the event (required).
 * @property {string} location - The location where the event will take place (required).
 * @property {mongoose.Types.ObjectId} organizer - Reference to the user who organized the event (required).
 * @property {Date} createdAt - Timestamp when the event was created (auto-generated).
 * @property {Date} updatedAt - Timestamp when the event was last updated (auto-generated).
 */

/**
 * Mongoose schema for the Event collection.
 * @constant
 * @type {mongoose.Schema<Event>}
 */
const eventSchema = new mongoose.Schema(
  {
    title: {
      type: String,
      required: true,
    },
    description: {
      type: String,
      required: true,
    },
    date: {
      type: Date,
      required: true,
    },
    location: {
      type: String,
      required: true,
    },
    organizer: {
      type: mongoose.Schema.Types.ObjectId,
      ref: "User",
      required: true,
    },
  },
  {
    timestamps: true, // adds createdAt and updatedAt
  }
);

/**
 * The Mongoose model for Event documents.
 * @type {mongoose.Model<Event>}
 */
const Event = mongoose.model("Event", eventSchema);

module.exports = Event;