require('dotenv').config();
const { createClient } = require('@supabase/supabase-js');
const sb = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_SERVICE_KEY);
(async()=>{
  const {data:tasks} = await sb.from('tasks')
    .select('id,title,created_at,expires_at,current_workers,max_workers')
    .eq('status','full')
    .order('created_at',{ascending:true});
  console.log('Full tasks:',tasks.length);
  for(const t of tasks){
    const {data:subs} = await sb.from('submissions')
      .select('id,status,created_at,worker_id')
      .eq('task_id',t.id);
    const daysOld = Math.floor((new Date()-new Date(t.created_at))/86400000);
    console.log('\n---');
    console.log('Title:',t.title.slice(0,60));
    console.log('Days old:',daysOld,'| Expires:',t.expires_at ? t.expires_at.slice(0,10) : 'never');
    console.log('Submissions:',subs.length, subs.map(s=>s.status).join(', '));
  }
})();
