const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function main() {
  // 查找3D打印作品大赛
  const contest = await prisma.contest.findFirst({
    where: { contestName: { contains: '3D打印' } }
  });

  if (!contest) {
    console.log('未找到3D打印作品大赛');
    return;
  }

  console.log(`赛事: ${contest.contestName} (ID: ${contest.id})\n`);

  // 查找该赛事的所有报名记录
  const registrations = await prisma.contestRegistration.findMany({
    where: { contestId: contest.id },
    include: {
      user: true,
      contest: true
    }
  });

  console.log(`报名记录数量: ${registrations.length}\n`);

  if (registrations.length > 0) {
    console.log('报名记录详情:');
    registrations.forEach(r => {
      console.log(`  ID: ${r.id}, 用户: ${r.user?.username || 'N/A'}, 租户ID: ${r.tenantId}, 状态: ${r.status}`);
    });
  }

  // 查找 xuesheng1 用户
  const user = await prisma.user.findFirst({
    where: { username: 'xuesheng1' }
  });

  if (user) {
    console.log(`\nxuesheng1 用户信息:`);
    console.log(`  ID: ${user.id}, 租户ID: ${user.tenantId}`);

    // 查找该用户的所有报名记录
    const userRegistrations = await prisma.contestRegistration.findMany({
      where: { userId: user.id },
      include: { contest: true }
    });

    console.log(`\nxuesheng1 的所有报名记录 (${userRegistrations.length}):`);
    userRegistrations.forEach(r => {
      console.log(`  赛事: ${r.contest?.contestName}, 状态: ${r.status}, 租户ID: ${r.tenantId}`);
    });
  } else {
    console.log('\n未找到 xuesheng1 用户');
  }
}

main()
  .then(() => prisma.$disconnect())
  .catch(e => {
    console.error(e);
    prisma.$disconnect();
  });
