
import { NextResponse } from "next/server"
import { auth } from "@/lib/auth"
import { db } from "@/lib/db"

export async function GET() {
  const session = await auth()
  if (!session?.user?.email) {
    return NextResponse.json({ count: 0 })
  }

  const user = await db.user.findUnique({
    where: { email: session.user.email },
    select: { id: true },
  })

  if (!user) return NextResponse.json({ count: 0 })

  const count = await db.notificationRecipient.count({
    where: {
      userId: user.id,
      readAt: null,
    },
  })

  return NextResponse.json({ count })
}