import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function inspectMatch(matchId: string) {
  console.log(`Inspecting Match: ${matchId}`);

  // 1. Ana Mac Bilgileri
  const match = await prisma.match.findUnique({
    where: { id: matchId },
    include: {
      homeTeam: true,
      awayTeam: true,
      league: true,
    }
  });

  if (!match) {
    console.log("Mac bulunamadi!");
    return;
  }

  console.log(`\nLeague: ${match.league?.name} (${match.sport})`);
  console.log(`Match: ${match.matchName}`);
  console.log(`Date: ${new Date(Number(match.mstUtc)).toLocaleString()}`);
  console.log(`Status: ${match.status} (Score: ${match.scoreHome}-${match.scoreAway}) (HT: ${match.htScoreHome}-${match.htScoreAway})`);

  // 2. Istatistikler
  const stats = await prisma.footballTeamStats.findMany({
    where: { matchId }
  });
  console.log("\nStats:");
  stats.forEach(s => {
    const teamName = s.teamId === match.homeTeamId ? "Home" : "Away";
    console.log(`   ${teamName}: Ball: %${s.possessionPercentage}, Shots: ${s.totalShots} (${s.shotsOnTarget} on target), Pass: ${s.totalPasses}`);
  });

  // 3. Olaylar
  const events = await prisma.matchPlayerEvents.findMany({
    where: { matchId },
    orderBy: { id: 'asc' },
    include: { player: true }
  });
  console.log("\nEvents:");
  events.forEach(e => {
    console.log(`   [${e.timeMinute}'] ${e.eventType} - ${e.player?.name} (${e.eventSubtype || ''})`);
  });

  // 4. Oranlar
  const odds = await prisma.oddCategory.findMany({
    where: { matchId },
    include: { selections: true },
    take: 5 
  });
  console.log("\nOdds (Sample):");
  odds.forEach(cat => {
    console.log(`   Category: ${cat.name}`);
    cat.selections.forEach(sel => {
      console.log(`      - ${sel.name}: ${sel.oddValue}`);
    });
  });
}

inspectMatch(process.argv[2])
  .catch(e => console.error(e))
  .finally(async () => await prisma.$disconnect());