const authenticateToken = require('./authMiddleware');

// Admin middleware - checks if user is authenticated and is an admin
const requireAdmin = (req, res, next) => {
    // First authenticate the token
    authenticateToken(req, res, () => {
        // Check if user is admin
        if (!req.user || req.user.role !== 'admin') {
            return res.status(403).json({ 
                error: 'Access denied. Admin privileges required.',
                message: 'Only administrators can perform this action.'
            });
        }
        next();
    });
};

module.exports = requireAdmin;

