import { PrismaClient } from '@prisma/client';
import * as dotenv from 'dotenv';

dotenv.config();

(BigInt.prototype as any).toJSON = function () {
  return this.toString();
};

const prisma = new PrismaClient();

const matchId = '9jx9757cgs6exshzg12qnwp3o';

async function analyzeMiss() {
  const match = await prisma.liveMatch.findUnique({
    where: { id: matchId },
  });

  if (!match) {
    console.log('Match not found');
    return;
  }

  console.log('🔍 POST-MORTEM ANALYSIS: Montpellier vs Troyes (2-2)');
  console.log('='.repeat(80));

  console.log('\n❌ PREDICTION vs ACTUAL:');
  console.log('   Predicted: Under 2.5 goals (72.9% confidence)');
  console.log('   Actual: 2-2 (4 goals)');
  console.log('   xG Predicted: 1.07 - 1.09 (Total: 2.15)');
  console.log('   Error: Model UNDERESTIMATED goals by ~1.85');

  console.log('\n📊 ENGINE BREAKDOWN:');
  console.log('   Team Signal: 29.2% (LOW)');
  console.log('   Player Signal: 80%');
  console.log('   Odds Signal: 91.9% (VERY HIGH - DOMINANT)');
  console.log('   Referee Signal: 80%');
  console.log('\n   ⚠️ PROBLEM: Model %91.9 oranlara güvenmiş,');
  console.log('   ama oranlar YANILTIYDİ (bookmakers da düşük gol bekledi)');

  console.log('\n🎲 INHERENT UNCERTAINTY:');
  console.log('   Confidence: 72.9% = 27.1% chance of being WRONG');
  console.log('   Bu maç o %27 lik dilime düştü');

  console.log('\n📈 SYSTEMIC ISSUES TO INVESTIGATE:');
  console.log('   1. Odds signal çok baskın (%91.9) - model kendi xG sini düşük tutmuş');
  console.log('   2. Team signal düşük (%29.2) - form verisi yetersiz?');
  console.log('   3. V25 signal available: false - ensemble eksik');
  console.log('   4. Lineup var ama oyuncu formu hesaba katılmamış olabilir');

  await prisma.$disconnect();
}

analyzeMiss().catch(console.error);
