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

async function checkBooks() {
  console.log('\n📊 检查书籍列表：\n');
  
  const books = await prisma.book.findMany({
    orderBy: { id: 'desc' },
    take: 20,
    select: {
      id: true,
      title: true,
      description: true,
      userId: true,
      isPublished: true,
      createdAt: true,
      _count: {
        select: { chapters: true }
      }
    }
  });
  
  console.log(`最近20本书籍：\n`);
  books.forEach((book, index) => {
    console.log(`${index + 1}. ID: ${book.id}`);
    console.log(`   标题: ${book.title}`);
    console.log(`   描述: ${book.description}`);
    console.log(`   用户: ${book.userId}`);
    console.log(`   公开: ${book.isPublished}`);
    console.log(`   章节数: ${book._count.chapters}`);
    console.log(`   创建时间: ${book.createdAt}\n`);
  });
  
  // 统计标题为"我的音频"的书籍
  const myAudioBooks = await prisma.book.count({
    where: {
      title: '我的音频'
    }
  });
  
  console.log(`\n📈 标题为"我的音频"的书籍数量: ${myAudioBooks}\n`);
  
  await prisma.$disconnect();
}

checkBooks().catch(console.error);
