const mongoose = require("mongoose")

const notificationSchema = new mongoose.Schema({

  userId: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true }, // agent
  orgId: { type: mongoose.Schema.Types.ObjectId, ref: "Organization" },
  title: { type: String,  },        // "Work Assigned"
  message: { type: String,  },      // description text
  type: {
    type: String,
    enum: [
      "TASK_ASSIGNED",
      "ATTENDANCE_ALERT",
      "SECURITY_UPDATE",
      "PAYROLL",
      "SYSTEM",
      "LOGIN",
    ],
    // required: true,
  },

  icon: { type: String }, // optional (frontend mapping also OK)
  metadata: {
    taskId: { type: mongoose.Schema.Types.ObjectId,   ref: "Task", },
    // attendanceId: { type: mongoose.Schema.Types.ObjectId },
  },
  isRead: { type: Boolean, default: false },
//   audit 
  createdBy : { type: mongoose.Schema.Types.ObjectId, ref: "User" },
  createdAt: { type: Date, default: Date.now },
  isDeleted: { type: Boolean, default: false },
},
 {
    timestamps: true,
  });

  module.exports = mongoose.model("Notification", notificationSchema);
  