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

(async () => {
  try {
    const { data: tasks, error } = await sb
      .from('tasks')
      .select('id, category, title, max_workers, source')
      .order('category')
      .order('title');

    if (error) {
      console.error('❌ Error:', error.message);
      return;
    }

    if (!tasks || tasks.length === 0) {
      console.log('No tasks found');
      return;
    }

    const byCategory = {};
    tasks.forEach(t => {
      if (!byCategory[t.category]) {
        byCategory[t.category] = [];
      }
      byCategory[t.category].push(t);
    });

    console.log('\n📋 ALL TASKS - DETAILED LIST:\n');
    
    Object.keys(byCategory).sort().forEach(cat => {
      console.log(`\n${cat.toUpperCase()} (${byCategory[cat].length} tasks):`);
      
      byCategory[cat].forEach((t, i) => {
        console.log(`  ${i+1}. ${t.title}`);
      });
    });

  } catch (err) {
    console.error('❌ Error:', err.message);
  }
})();
