#!/usr/bin/env npx tsx
require('dotenv').config({ path: '.env.local' });
require('dotenv').config({ path: '.env' });

import { getSportsDb } from '../lib/sportsDb';

async function main() {
  const prisma = getSportsDb();

  // Check all unique team names in NHL
  console.log('\n=== NHL Teams ===');
  const nhlHome = await prisma.sportsGame.findMany({
    where: { league: 'nhl' },
    distinct: ['homeTeam'],
    select: { homeTeam: true },
  });
  const nhlAway = await prisma.sportsGame.findMany({
    where: { league: 'nhl' },
    distinct: ['awayTeam'],
    select: { awayTeam: true },
  });
  const nhlTeams = new Set([
    ...nhlHome.map((g: any) => g.homeTeam),
    ...nhlAway.map((g: any) => g.awayTeam),
  ]);
  console.log([...nhlTeams].sort().join('\n'));

  // Check NBA for the BNZ team
  console.log('\n=== NBA Teams ===');
  const nbaHome = await prisma.sportsGame.findMany({
    where: { league: 'nba' },
    distinct: ['homeTeam'],
    select: { homeTeam: true },
  });
  const nbaAway = await prisma.sportsGame.findMany({
    where: { league: 'nba' },
    distinct: ['awayTeam'],
    select: { awayTeam: true },
  });
  const nbaTeams = new Set([
    ...nbaHome.map((g: any) => g.homeTeam),
    ...nbaAway.map((g: any) => g.awayTeam),
  ]);
  console.log([...nbaTeams].sort().join('\n'));

  // Check if MLB has wrong data
  console.log('\n=== MLB Sample Games ===');
  const mlbSamples = await prisma.sportsGame.findMany({
    where: { league: 'mlb' },
    take: 10,
    orderBy: { gameDate: 'desc' },
    select: { homeTeam: true, awayTeam: true, gameDate: true, season: true },
  });
  for (const g of mlbSamples) {
    console.log(`${g.awayTeam} @ ${g.homeTeam} (${g.gameDate}) season=${g.season}`);
  }
}

main().catch(console.error);
