const { prisma } = require('../src/models');
(async () => {
  // TtsTask stats
  const total = await prisma.ttsTask.count();
  console.log(`TtsTask total: ${total}`);
  
  // Check for duplicates
  const dupCheck = await prisma.ttsTask.groupBy({
    by: ['chapterId'], _count: { id: true }, having: { id: { _count: { gt: 1 } } },
  });
  console.log(`Duplicates found: ${dupCheck.length}`);
  for (const d of dupCheck)
    console.log(`  ⚠️ chapterId=${d.chapterId}: ${d._count.id} entries`);
  
  // Check status distribution
  const byStatus = await prisma.ttsTask.groupBy({ by: ['status'], _count: { id: true } });
  console.log('\nStatus distribution:');
  for (const s of byStatus) console.log(`  ${s.status}: ${s._count.id}`);
  
  // All unique chapterIds
  const chapters = await prisma.ttsTask.findMany({ select: { chapterId: true, status: true, id: true }, orderBy: { id: 'asc' }, take: 10 });
  console.log('\nFirst 10 tasks:');
  for (const c of chapters) console.log(`  #${c.id} chapterId=${c.chapterId} ${c.status}`);
  
  await prisma.$disconnect();
})();
