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

async function forceClear() {
  try {
    console.log('🗑️  强制清空 bookId=1 的所有数据...\n');
    
    // 先删除所有章节
    const deleteResult = await prisma.bookChapter.deleteMany({
      where: { bookId: 1 }
    });
    console.log(`✅ 已删除 ${deleteResult.count} 条章节记录`);
    
    // 重置书籍状态
    await prisma.book.update({
      where: { id: 1 },
      data: {
        status: 'draft',
        progress: 0,
        errorMsg: null,
        outlineJson: null  // 也清空outlineJson
      }
    });
    console.log('✅ 书籍状态已重置');
    
    // 验证
    const count = await prisma.bookChapter.count({
      where: { bookId: 1 }
    });
    console.log(`\n📊 验证: bookId=1 的章节记录数: ${count}`);
    
    if (count === 0) {
      console.log('✅ 清空成功！数据库现在是干净的');
    } else {
      console.log('❌ 还有残留数据！');
    }

  } catch (error) {
    console.error('错误:', error);
  } finally {
    await prisma.$disconnect();
  }
}

forceClear();
