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

(async () => {
  console.log('\n🗑️  DELETING ALL OLD TASKS...\n');
  
  try {
    // Get count of tasks
    const { data: allTasks } = await sb
      .from('tasks')
      .select('id');
    
    if (!allTasks || allTasks.length === 0) {
      console.log('No tasks to delete');
      return;
    }
    
    console.log(`Found ${allTasks.length} tasks. Deleting all...`);
    
    // Delete using created_at filter (matches everything)
    const { count, error } = await sb
      .from('tasks')
      .delete()
      .gt('created_at', '1900-01-01')
      .select('id', { count: 'exact', head: true });
    
    if (error) {
      console.error('Error:', error.message);
      return;
    }
    
    console.log(`✅ Deleted ${count || allTasks.length} tasks\n`);
    
  } catch (e) {
    console.error('Error:', e.message);
  }
})();
