import { NextRequest, NextResponse } from 'next/server' import prisma from '@/lib/prisma' import { getAuthUser } from '@/lib/auth-utils' export async function GET(request: NextRequest) { try { const authUser = await getAuthUser(request) if (!authUser) { return NextResponse.json({ error: 'Utilisateur non identifié' }, { status: 401 }) } const userId = authUser.id const unreadCount = await prisma.message.count({ where: { conversation: { participants: { some: { userId: userId } } }, senderId: { not: userId }, read: false } }) return NextResponse.json({ count: unreadCount }) } catch (error) { console.error('GET /api/messages/unread error:', error) return NextResponse.json({ error: 'Erreur serveur' }, { status: 500 }) } }