import User from '../models/User.js'; export const updateKarma = async (userId, change, reason) => { try { const user = await User.findById(userId); if (!user) return; // Calculate new score let newScore = user.karma + change; // Clamp between 0 and 100 if (newScore > 100) newScore = 100; if (newScore < 0) newScore = 0; user.karma = newScore; // Auto-Ban Logic (Bible Rule: < 30) if (newScore < 30) { user.flags.isBanned = true; console.log(`🚫 BANNED User ${userId} (Karma: ${newScore})`); } // Log the reason (for future admin tools) // In MVP, we just console log, but we could push to a 'karmaHistory' array console.log(`Karma Update [${userId}]: ${change} (${reason}) => ${newScore}`); await user.save(); return user; } catch (err) { console.error("Karma Update Failed", err); } };