const prisma = require("../lib/prisma");
const generateSubjectThumbnail = require("../utils/generateSubjectThumbnail");

async function regenerateAll() {
  const subjects = await prisma.subject.findMany({ include: { teacher: true } });
  for (const s of subjects) {
    const url = await generateSubjectThumbnail(
      { title: s.title, teacherName: `${s.teacher.firstName} ${s.teacher.lastName}`, price: s.price, enrollment: s.enrollment },
    );
    await prisma.subject.update({ where: { id: s.id }, data: { thumbnailUrl: url } });
    console.log(`Updated: ${s.title}`);
  }
  console.log("All thumbnails regenerated ✅");
}

regenerateAll().then(() => process.exit());
