const { prisma } = require('../src/models');
(async () => {
  const bookId = 53;
  
  // Reset chapters to content_completed, clear audioUrl
  const result = await prisma.bookChapter.updateMany({
    where: { bookId, content: { not: null } },
    data: { genStage: 'content_completed', audioUrl: '', audioDuration: 0, lrcLyrics: '' },
  });
  console.log(`Reset ${result.count} chapters to content_completed`);
  
  // Delete failed TtsTasks for this book
  const del = await prisma.ttsTask.deleteMany({
    where: { bookId, status: 'failed' }
  });
  console.log(`Deleted ${del.count} failed TtsTasks`);
  
  // Update book genStage
  await prisma.book.update({ where: { id: bookId }, data: { genStage: 'content_completed' } });
  console.log('Book #53 reset to content_completed. Ready for TTS retry test.');
  
  await prisma.$disconnect();
})();
