const mongoose = require('mongoose'); const auditLogSchema = new mongoose.Schema({ action: { type: String, required: true }, actor: { type: mongoose.Schema.Types.ObjectId, ref: 'Admin', required: true }, targetType: { type: String }, targetId: { type: mongoose.Schema.Types.ObjectId }, details: { type: mongoose.Schema.Types.Mixed }, ipAddress: { type: String }, timestamp: { type: Date, default: Date.now }, }); auditLogSchema.index({ actor: 1, timestamp: -1 }); auditLogSchema.index({ targetType: 1, targetId: 1 }); auditLogSchema.index({ action: 1 }); module.exports = mongoose.model('AuditLog', auditLogSchema);