import { prisma } from '../../lib/db';
import { VOCAB } from '@/lib/white-label/constants';

async function clearDarkFactory() {
  console.log(`🗑️  Clearing ${VOCAB.factory} data...\n`);

  // Delete in order of dependencies (children first)
  
  // 1. Delete GeneratedArtifacts
  const artifacts = await prisma.generatedArtifact.deleteMany({});
  console.log(`✓ Deleted ${artifacts.count} artifacts`);

  // 2. Delete ValidationResults
  const validations = await prisma.validationResult.deleteMany({});
  console.log(`✓ Deleted ${validations.count} validation results`);

  // 3. Delete Deployments
  const deployments = await prisma.deployment.deleteMany({});
  console.log(`✓ Deleted ${deployments.count} deployments`);

  // 4. Delete GenerationTasks
  const tasks = await prisma.generationTask.deleteMany({});
  console.log(`✓ Deleted ${tasks.count} tasks`);

  // 5. Delete GenerationRequests
  const requests = await prisma.generationRequest.deleteMany({});
  console.log(`✓ Deleted ${requests.count} requests`);

  // 6. Delete FactoryEvents
  const events = await prisma.factoryEvent.deleteMany({});
  console.log(`✓ Deleted ${events.count} factory events`);

  console.log(`\n✅ ${VOCAB.factory} cleared!`);
}

clearDarkFactory()
  .catch(console.error)
  .finally(() => prisma.$disconnect());
