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

async function checkContentStatus() {
  console.log('\n📊 检查contentStatus状态：\n');
  
  const chapterId = 1163;
  
  const chapter = await prisma.bookChapter.findUnique({
    where: { id: chapterId }
  });
  
  if (!chapter) {
    console.log('❌ 找不到该章节\n');
    await prisma.$disconnect();
    return;
  }
  
  console.log(`章节: ${chapter.title}`);
  console.log(`ID: ${chapter.id}`);
  console.log(`BookId: ${chapter.bookId}`);
  console.log(`Level: ${chapter.level}`);
  console.log(`内容: ${chapter.content || '无'}`);
  console.log(`contentStatus: ${chapter.contentStatus || 'null'}`);
  console.log(`audioStatus: ${chapter.audioStatus || 'null'}`);
  console.log('');
  
  // 统计该书各状态的小节数量
  const statusCount = await prisma.bookChapter.groupBy({
    by: ['contentStatus'],
    where: {
      bookId: chapter.bookId,
      level: 3
    },
    _count: true
  });
  
  console.log(`📈 BookId ${chapter.bookId} 小节内容状态统计：\n`);
  statusCount.forEach(s => {
    console.log(`  ${s.contentStatus || 'null'}: ${s._count}个`);
  });
  
  console.log('\n');
  
  await prisma.$disconnect();
}

checkContentStatus().catch(console.error);
