// models/activityLog.model.js
const mongoose = require('mongoose');

const activityLogSchema = new mongoose.Schema({
  adminId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Account',
    required: true,
  },
  action: {
    type: String,
    required: true,
    enum: ['ADD_ADMIN', 'EDIT_ADMIN_DETAILS', 'SUSPEND_ACCOUNT', 'BAN_ACCOUNT', 
           'VERIFY_USER', 'REVOKE_USER_VERIFICATION', 'APPROVE_PRODUCT', 
           'REJECT_PRODUCT', 'VERIFY_PRODUCT', 'ADD_STORE', 'UPDATE_STORE', 
           'DELETE_STORE', 'TOGGLE_BADGE', 'PROMOTE_ADMIN', 'REMOVE_ADMIN', 
           'DELETE_USER'],
  },
  description: {
    type: String,
    required: true,
  },
  targetType: {
    type: String,
    enum: ['account', 'product', 'order', 'transaction', 'store', 'category'],
    required: true,
  },
  targetId: {
    type: mongoose.Schema.Types.ObjectId,
    required: true,
  },
  metadata: {
    type: mongoose.Schema.Types.Mixed,
    default: {},
  },
  ipAddress: String,
  userAgent: String,
}, {
  timestamps: true,
});

// Index for efficient querying
activityLogSchema.index({ adminId: 1, createdAt: -1 });
activityLogSchema.index({ targetType: 1, targetId: 1 });
activityLogSchema.index({ createdAt: -1 });
activityLogSchema.index({ action: 1 });

module.exports = mongoose.model('ActivityLog', activityLogSchema);