const ADMIN_URL = 'https://ecobeadmin.com/admin/api';
const BOT_TOKEN = '15579990079586356780';

const headers = { 'Authorization': `Bearer ${BOT_TOKEN}` };
async function get(path) {
    const r = await fetch(`${ADMIN_URL}${path}`, { headers });
    if (!r.ok) throw new Error(`${r.status} ${path}`);
    return r.json();
}

const planLabel = { silver: 'Self-Driven', golden: 'Partnership' };

async function main() {
    const slugs = await get('/mentees');
    const clients = [];

    for (const slug of slugs) {
        try {
            const cs = await get(`/mentee/${slug}/career-strategy`);
            clients.push({
                name:    cs.leadName || slug,
                phone:   cs.phone   || '—',
                email:   cs.email   || '—',
                plan:    planLabel[cs.plan] || cs.plan || '—',
                entryDate: cs.entryDate || cs.createdAt || null,
            });
        } catch {}
    }

    clients.sort((a, b) => (b.entryDate || '') > (a.entryDate || '') ? 1 : -1);

    console.log(`\nTotal clients: ${clients.length}\n`);
    clients.forEach((c, i) => {
        const date = c.entryDate ? new Date(c.entryDate).toLocaleDateString('pt-BR') : '—';
        console.log(`${String(i + 1).padStart(2)}. ${c.name}`);
        console.log(`    📱 ${c.phone}  ✉  ${c.email}  📋 ${c.plan}  📅 ${date}`);
    });
    console.log();
}

main().catch(console.error);
