const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function checkAudioStatus() {
  const bookId = 5;
  
  // 查找已完成内容的小节
  const subsections = await prisma.bookChapter.findMany({
    where: {
      bookId,
      level: 3,
      contentStatus: 'completed'
    },
    select: {
      id: true,
      title: true,
      wordCount: true,
      audioUrl: true,
      audioDuration: true,
    },
    orderBy: { id: 'asc' },
    take: 10
  });
  
  console.log('\n Book 5 小节音频生成状态检查：\n');
  console.log('=' .repeat(80));
  
  const withAudio = subsections.filter(s => s.audioUrl);
  const withoutAudio = subsections.filter(s => !s.audioUrl);
  
  console.log(`\n✅ 已有音频的小节：${withAudio.length}个`);
  withAudio.forEach((sub, index) => {
    console.log(`  ${index + 1}. ${sub.title} (${sub.wordCount}字, ${sub.audioDuration || 0}秒)`);
  });
  
  console.log(`\n❌ 未生成音频的小节：${withoutAudio.length}个`);
  withoutAudio.slice(0, 5).forEach((sub, index) => {
    console.log(`  ${index + 1}. ${sub.title} (${sub.wordCount}字)`);
  });
  if (withoutAudio.length > 5) {
    console.log(`  ... 还有${withoutAudio.length - 5}个`);
  }
  
  console.log('\n' + '='.repeat(80));
  
  // 检查audio表
  const audioRecords = await prisma.audio.count({
    where: { bookId }
  });
  
  console.log(`\n📊 Audio表记录数: ${audioRecords}`);
  
  await prisma.$disconnect();
}

checkAudioStatus().catch(console.error);
