const { PrismaClient } = require('@prisma/client');
const p = new PrismaClient({ datasourceUrl: 'postgresql://mopc:devpassword@localhost:5433/mopc' });

(async () => {
  const members = await p.teamMember.findMany({
    orderBy: { joinedAt: 'desc' },
    take: 10,
    include: {
      user: { select: { id: true, name: true, email: true, status: true, inviteToken: true } },
      project: { select: { title: true } }
    }
  });
  for (const m of members) {
    console.log(m.role, '|', m.user.name, '|', m.user.email, '|', m.user.status, '|', m.project.title, '|', m.joinedAt.toISOString().slice(0,16), '| token:', m.user.inviteToken ? 'yes' : 'no');
  }

  const logs = await p.notificationLog.findMany({
    where: { type: 'TEAM_INVITATION' },
    orderBy: { createdAt: 'desc' },
    take: 5,
  });
  if (logs.length) {
    console.log('\n--- Notification logs:');
    for (const l of logs) {
      console.log(l.status, '|', l.channel, '|', l.errorMsg, '|', l.createdAt.toISOString().slice(0,16));
    }
  } else {
    console.log('\n--- No TEAM_INVITATION notification logs found');
  }

  await p.$disconnect();
})();
