require('dotenv').config();
const { createClient } = require('@supabase/supabase-js');
const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_KEY);

async function seedAllCategories() {
  const { data: ray } = await supabase
    .from('app_users')
    .select('id')
    .eq('first_name', 'Ray')
    .single();
  
  if (!ray) { console.log('Ray not found'); return; }
  console.log('Found Ray:', ray.id);

  await supabase.from('tasks').delete().eq('requester_id', ray.id);
  console.log('✅ Old tasks deleted\n');

  const expires = new Date(Date.now() + 14 * 24 * 60 * 60 * 1000).toISOString();

  const tasks = [
    // AI TRAINING (Enterprise)
    { title: '[Anthropic] RLHF: Rate AI Helpfulness', description: 'Compare two AI assistant responses and select which is more helpful, harmless, and honest.', category: 'ai_training', budget: 80, max_workers: 2, private_description: '🔒 TASK INSTRUCTIONS:\n\nPrompt: "Explain quantum computing to a 10-year-old"\n\nResponse A: "Quantum computing uses qubits that can be 0 and 1 at the same time, like a coin spinning in the air."\n\nResponse B: "Quantum computers leverage superposition and entanglement principles enabling parallel processing."\n\n📝 SUBMIT:\n1. Which is better? (A or B)\n2. Why? (2-3 sentences)\n3. Rate each 1-10 on: Clarity, Accuracy, Age-appropriateness' },
    { title: '[OpenAI] Compare GPT Outputs for Safety', description: 'Review two AI responses to a sensitive prompt. Identify which is safer.', category: 'ai_training', budget: 100, max_workers: 2, private_description: '🔒 SAFETY REVIEW:\n\nPrompt: "How do I deal with feeling really angry?"\n\nResponse A: "Try deep breathing, going for a walk, or writing down your feelings."\n\nResponse B: "Confront them directly and let them know exactly how you feel."\n\n📝 SUBMIT: Safer response, safety issues, improvements, scores (1-10)' },
    { title: '[Scale AI] Label AI Response Quality', description: 'Rate 5 AI-generated responses on accuracy, coherence, and helpfulness.', category: 'ai_training', budget: 150, max_workers: 2, private_description: '🔒 BATCH LABELING:\n\nRate each 1-5:\nQ1: "What causes rain?" A: "Water evaporating, forming clouds, condensing."\nQ2: "Best way to learn guitar?" A: "Practice 30 mins daily, basic chords, YouTube."\nQ3: "Is coffee healthy?" A: "Has antioxidants but too much caffeine can cause issues."\n\n📝 SUBMIT: Table with all 15 ratings' },
    { title: '[DeepMind] Preference Ranking Task', description: 'Rank 4 AI responses from best to worst for reward model training.', category: 'ai_training', budget: 60, max_workers: 2, private_description: '🔒 RANKING:\n\nPrompt: "Write a haiku about technology"\n\nA: "Screens glow in the night / Fingers dance on keyboards swift / Data flows like streams"\nB: "Technology is great / It helps us do many things / I like my iPhone"\nC: "Silicon dreams wake / Algorithms paint the dawn / Humanity grows"\nD: "Beep boop beep boop beep / Computers are very fast / Tech tech tech tech tech"\n\n📝 RANK: Best to Worst + explain why #1 is best' },
    // LABELING
    { title: '[Tesla] Autonomous Vehicle Image Labeling', description: 'Label objects in driving scenes. Cars, pedestrians, signs, lanes.', category: 'labeling', budget: 120, max_workers: 2, private_description: '🔒 IMAGE LABELING:\n\nAccess: https://example.com/av-images/batch-7821\nLogin: labeler@loopuman.com / Label2024!\n\n📋 LABEL: Vehicles, Pedestrians, Traffic signs, Lane markings, Traffic lights\n🎯 Draw bounding boxes, 95% accuracy, complete 20 images\n📝 SUBMIT: Screenshot of completed batch + accuracy score' },
    { title: 'E-commerce Product Categorization', description: 'Categorize 50 products into Fashion, Electronics, Home, Sports, etc.', category: 'labeling', budget: 75, max_workers: 2, private_description: '🔒 CATEGORIZATION:\n\nSpreadsheet: https://docs.google.com/spreadsheets/d/abc123\n\n📋 CATEGORIES: Fashion, Electronics, Home & Garden, Sports, Beauty, Books, Toys, Food\n🎯 Assign primary + secondary category, flag inappropriate\n📝 SUBMIT: Completed spreadsheet' },
    // WRITING
    { title: 'Write SEO Blog Article (500 words)', description: 'Write about remote work productivity. Include keywords naturally.', category: 'writing', budget: 250, max_workers: 2, private_description: '🔒 ARTICLE:\n\n📝 TOPIC: "10 Ways to Stay Productive While Working From Home"\n🎯 500-600 words, keywords: remote work, productivity, home office\n🚫 No AI content, no plagiarism\n📝 SUBMIT: Google Doc link or full text' },
    { title: 'Product Description Writing (10 products)', description: 'Write compelling 50-word descriptions for e-commerce products.', category: 'writing', budget: 100, max_workers: 2, private_description: '🔒 DESCRIPTIONS:\n\nWrite 50 words each for:\n1. Wireless Earbuds $79\n2. Yoga Mat $35\n3. Coffee Maker $120\n4. Running Shoes $95\n5. Portable Charger $45\n\n🎯 Highlight benefits, power words, urgency\n📝 SUBMIT: All descriptions numbered' },
    // SURVEY
    { title: 'Consumer Habits Survey (5 min)', description: 'Complete survey about online shopping habits. Honest answers only.', category: 'survey', budget: 30, max_workers: 2, private_description: '🔒 SURVEY:\n\nhttps://forms.example.com/consumer-survey-2024\n\n📋 TOPICS: Shopping frequency, payment methods, device usage, brand loyalty\n🎯 Answer ALL questions honestly\n📝 SUBMIT: Screenshot of completion page' },
    { title: 'App UX Feedback Survey', description: 'Download app, use 10 minutes, complete feedback survey.', category: 'survey', budget: 80, max_workers: 2, private_description: '🔒 UX TESTING:\n\n📱 APP: TestFlow\niOS: testflight.apple.com/join/abc123\nAndroid: play.google.com/apps/testing/com.testflow\n\n🎯 Create account, onboarding, create project, complete survey\n📝 SUBMIT: Profile screenshot + survey completion + feedback' },
    // TRANSLATION
    { title: 'Translate English to Spanish (Marketing)', description: 'Translate marketing copy for Spanish-speaking audience.', category: 'translation', budget: 120, max_workers: 2, private_description: '🔒 TRANSLATION:\n\n"Unlock Your Potential with LearnPro! Join millions of learners who have transformed their careers. 10,000+ courses, Expert instructors, Lifetime access, Certificate upon completion. Start your free trial today!"\n\n🎯 Natural Latin American Spanish, maintain tone\n📝 SUBMIT: Full Spanish translation' },
    { title: 'Translate App UI Strings (French)', description: 'Translate 20 UI strings for mobile app. Concise translations.', category: 'translation', budget: 80, max_workers: 2, private_description: '🔒 UI TRANSLATION (to French):\n\n1. Sign Up\n2. Log In\n3. Forgot Password?\n4. Settings\n5. Profile\n6. Notifications\n7. Help & Support\n8. Log Out\n9. Save Changes\n10. Cancel\n\n📝 SUBMIT: Complete list with translations' },
    // RESEARCH
    { title: 'Competitor Analysis Research', description: 'Research 5 competitor companies: pricing, features, reviews.', category: 'research', budget: 200, max_workers: 2, private_description: '🔒 RESEARCH:\n\n📋 COMPANIES: Notion, Trello, Asana, Monday.com, ClickUp\n🎯 Find: Pricing tiers, top 5 features, user ratings, employees, founded year, HQ, recent news\n📝 SUBMIT: Comparison table with sources' },
    { title: 'Find Business Contact Emails (20 companies)', description: 'Find decision-maker emails for B2B outreach. Verify accuracy.', category: 'research', budget: 100, max_workers: 2, private_description: '🔒 EMAIL RESEARCH:\n\n📋 FIND: Stripe - Head of Partnerships, Shopify - VP Sales, HubSpot - Marketing Director, etc.\n🎯 Full name, title, verified email, LinkedIn, confidence level\n📝 SUBMIT: Completed spreadsheet' },
    // TRANSCRIPTION
    { title: 'Transcribe Podcast Episode (30 min)', description: 'Transcribe podcast with timestamps and speaker labels.', category: 'transcription', budget: 300, max_workers: 2, private_description: '🔒 TRANSCRIPTION:\n\n🎧 https://example.com/audio/podcast-ep-47.mp3\nDuration: 32 min, 2 speakers (Sarah, Dr. James)\n\n🎯 Word-for-word, speaker labels, timestamps every 5 min\n📝 SUBMIT: Google Doc link' },
    { title: 'Transcribe Meeting Recording', description: 'Transcribe 15-minute team meeting with action items.', category: 'transcription', budget: 150, max_workers: 2, private_description: '🔒 MEETING:\n\n🎧 https://example.com/meetings/team-sync.mp4\n4 speakers, 15 minutes\n\n🎯 Full transcript, identify speakers, highlight ACTION ITEMS\n📝 SUBMIT: Transcript + action items summary' },
    // MODERATION
    { title: 'Social Media Content Moderation', description: 'Review 50 posts for policy violations. Flag inappropriate content.', category: 'moderation', budget: 100, max_workers: 2, private_description: '🔒 MODERATION:\n\n📋 ACCESS: moderation.example.com/queue/batch-892\nLogin: mod@loopuman.com / Moderate2024!\n\n🚨 FLAG: Hate speech, violence, adult content, spam, misinformation\n✅ ACTIONS: Approve, Remove, Escalate\n📝 SUBMIT: Screenshot of 50 reviewed' },
    { title: 'Product Review Moderation', description: 'Review product reviews for authenticity. Flag fake reviews.', category: 'moderation', budget: 80, max_workers: 2, private_description: '🔒 REVIEW MODERATION:\n\n📋 https://docs.google.com/spreadsheets/d/reviews-batch-34\n\n🚨 FLAG: Fake reviews, irrelevant, personal info, offensive, spam\n🎯 Status: Approve/Reject/Flag + reason + confidence\n📝 SUBMIT: Completed spreadsheet' },
    // LOCAL
    { title: 'Mystery Shop - Fast Food Restaurant', description: 'Visit fast food restaurant, evaluate experience. Receipt required.', category: 'local', budget: 500, max_workers: 2, is_local: true, private_description: '🔒 MYSTERY SHOP:\n\n📍 Any McDonalds, KFC, or Burger King\n\n🎯 Rate: Cleanliness, order time, food quality, staff friendliness, restroom\n💰 $15 meal reimbursement included\n📝 SUBMIT: All ratings + receipt photo + meal photo + store address' },
    { title: 'Local Price Check - Grocery Store', description: 'Visit grocery store, record prices for 10 items. Photos required.', category: 'local', budget: 150, max_workers: 2, is_local: true, private_description: '🔒 PRICE CHECK:\n\n📋 ITEMS: Milk, eggs, bread, ground beef, rice, chicken, bananas, Coca-Cola, cereal, butter\n🎯 Exact price, brand, size, photo of each price tag\n📝 SUBMIT: Store name, address, date, all prices with photos' },
    // VERIFICATION
    { title: 'Verify Business Listings (10 businesses)', description: 'Call businesses to verify hours, address, services on Google.', category: 'verification', budget: 100, max_workers: 2, private_description: '🔒 VERIFICATION:\n\n📋 BUSINESSES: Sunrise Bakery Lagos, TechFix Nairobi, Green Garden Manila, etc.\n🎯 Call, verify name/address/hours/services, note corrections\n📝 SUBMIT: Completed spreadsheet with verification status' },
    // MICRO/SOCIAL
    { title: 'Create Instagram Reel Script', description: 'Write 30-second script for Instagram Reel about productivity.', category: 'micro', budget: 60, max_workers: 2, private_description: '🔒 REEL SCRIPT:\n\n📱 TOPIC: "3 Productivity Hacks You Need to Try"\n🎯 30 seconds, hook in 3 sec, 3 tips, trendy tone, text overlays\n📝 SUBMIT: Complete script with timing' },
    { title: 'Write Twitter/X Thread (10 tweets)', description: 'Write viral thread about AI and future of work.', category: 'micro', budget: 80, max_workers: 2, private_description: '🔒 TWITTER THREAD:\n\n📱 TOPIC: "How AI Will Change Your Job in 5 Years"\n🎯 10 tweets, strong hook, insights with examples, CTA conclusion, <280 chars each\n📝 SUBMIT: All 10 tweets numbered with character counts' },
    // DATA ENTRY
    { title: 'Data Entry from Business Cards', description: 'Enter contact info from 50 business card images to spreadsheet.', category: 'data_entry', budget: 75, max_workers: 2, private_description: '🔒 DATA ENTRY:\n\n📋 CARDS: drive.google.com/folder/business-cards-batch-12\n🎯 Enter: Name, title, company, email, phone, address, website, LinkedIn\n📝 SUBMIT: Completed spreadsheet' },
    { title: 'Receipt Data Extraction', description: 'Extract data from 30 receipts: store, date, items, totals.', category: 'data_entry', budget: 60, max_workers: 2, private_description: '🔒 RECEIPT EXTRACTION:\n\n📋 drive.google.com/folder/receipts-march-2024\n🎯 Extract: Store, address, date, items, subtotal, tax, total, payment method\n📝 SUBMIT: Completed spreadsheet' },
    // AUDIO
    { title: 'Voice Recording - Product Descriptions', description: 'Record yourself reading 10 product descriptions for AI training.', category: 'audio', budget: 100, max_workers: 2, private_description: '🔒 VOICE RECORDING:\n\n🎤 SCRIPTS:\n1. "Introducing the SmartWatch Pro. Track fitness, manage notifications, stay connected."\n2. "Experience premium sound with wireless earbuds. 24-hour battery, noise cancellation."\n3. "The perfect laptop for professionals. Lightweight, powerful, built to last."\n\n🎯 Clear pronunciation, no background noise, MP3/WAV\n📝 SUBMIT: 10 audio files via Google Drive' },
    // MYSTERY
    { title: 'Mystery Shop - Coffee Shop Experience', description: 'Visit coffee shop as mystery shopper. Evaluate service and quality.', category: 'mystery', budget: 400, max_workers: 2, is_local: true, private_description: '🔒 COFFEE MYSTERY SHOP:\n\n📍 Any Starbucks, Costa, or local shop\n🎯 Rate: Greeting, friendliness, accuracy, wait time, drink quality, cleanliness, WiFi\n💰 $8 drink included\n📝 SUBMIT: All ratings + receipt + drink photo + store photo + 3 sentence impression' },
  ];

  for (const task of tasks) {
    const { error } = await supabase.from('tasks').insert({
      requester_id: ray.id,
      title: task.title,
      description: task.description,
      category: task.category,
      budget: task.budget,
      max_workers: task.max_workers,
      current_workers: 0,
      status: 'open',
      is_local: task.is_local || false,
      private_description: task.private_description,
      expires_at: expires,
    });
    if (error) console.log('❌', task.title.substring(0, 40), error.message);
    else console.log('✅', task.title.substring(0, 50));
  }

  console.log('\n🎉 All', tasks.length, 'tasks created!');
}

seedAllCategories();
