/**
 * 清空經營工作區資料，保留 User / Session / Account / Setting / AutomationRule。
 * 用法：npx tsx scripts/clear-workspace-data.ts
 */
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function main() {
  const counts = {
    outreachDrafts: await prisma.outreachDraft.deleteMany(),
    outreachTargets: await prisma.outreachTarget.deleteMany(),
    replyDrafts: await prisma.replyDraft.deleteMany(),
    inboundReplies: await prisma.inboundReply.deleteMany(),
    performanceSnapshots: await prisma.performanceSnapshot.deleteMany(),
    published: await prisma.published.deleteMany(),
    drafts: await prisma.draft.deleteMany(),
    replies: await prisma.reply.deleteMany(),
    scans: await prisma.scan.deleteMany(),
    topics: await prisma.topic.deleteMany(),
    productProfiles: await prisma.productProfile.deleteMany(),
    backgroundJobs: await prisma.backgroundJob.deleteMany(),
    actionLogs: await prisma.actionLog.deleteMany(),
  };

  console.log("已清理工作區資料：");
  for (const [table, result] of Object.entries(counts)) {
    console.log(`  ${table}: ${result.count} 筆`);
  }
  console.log("\n保留：使用者、登入 session、經營帳號、系統設定、自動化規則、Threads 連線。");
}

main()
  .catch((err) => {
    console.error(err);
    process.exit(1);
  })
  .finally(() => prisma.$disconnect());