import type { Request, Response, NextFunction } from 'express';
import { prisma } from '../config/database.js';

export async function checkBanned(req: Request, res: Response, next: NextFunction): Promise<void> {
  if (!req.userId) {
    next();
    return;
  }

  const user = await prisma.user.findUnique({
    where: { id: req.userId },
    select: { isBanned: true, banReason: true },
  });

  if (user?.isBanned) {
    res.status(403).json({
      message: 'Account suspended',
      reason: user.banReason || 'Your account has been suspended. Contact support for more information.',
    });
    return;
  }

  next();
}
