import { prisma } from "@/lib/db/prisma";

type StudentNotification = {
  title: string;
  message?: string;
  type: "MATERIAL" | "ARTICLE" | "PROJECT" | "DOWNLOAD";
  href?: string;
};

export async function notifyActiveStudents(notification: StudentNotification) {
  const students = await prisma.student.findMany({
    where: { status: "ACTIVE", userId: { not: null }, user: { status: "ACTIVE" } },
    select: { userId: true },
  });
  if (!students.length) return;
  await prisma.notification.createMany({
    data: students.flatMap(({ userId }) => userId ? [{ userId, ...notification }] : []),
  });
}
