require('dotenv').config();
const { createClient } = require('@supabase/supabase-js');
const sb = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_KEY);
(async()=>{
  // Get Ray's active tasks
  const {data:tasks} = await sb.from('tasks')
    .select('id,title,status,created_at,expires_at,current_workers,max_workers,source,category')
    .eq('requester_id','97c472eb-7db6-4639-90f0-a48047b2e46e')
    .eq('status','active')
    .order('created_at',{ascending:true});
  
  console.log('Active tasks:',tasks.length);
  for(const t of tasks){
    // Get submissions for this task
    const {data:subs} = await sb.from('submissions')
      .select('id,status,created_at,worker_id')
      .eq('task_id',t.id);
    console.log('\n---');
    console.log('Title:',t.title.slice(0,60));
    console.log('Created:',t.created_at.slice(0,10),'Expires:',t.expires_at ? t.expires_at.slice(0,10) : 'never');
    console.log('Workers:',t.current_workers,'/',t.max_workers);
    console.log('Submissions:',subs.length, subs.map(s=>s.status).join(', '));
  }
})();
