const AuditLog = require("../models/auditLog");
const RequestMeta = require("../utils/requestMeta");
async function writeAuditLog({
  model,
  documentId,
  action,
  before,
  after,
  changes = [],
  req,
}) {
  await AuditLog.create({
    model,
    documentId,
    action,
    before,
    after,
    changes,
    ipAddress: RequestMeta.getClientIp(req),
    userAgent: RequestMeta.getUserAgent(req),
    performedBy: req.session?.user?.id || req.user?.id || null,
  });
}

module.exports = writeAuditLog;
