function phiCoefficient(p11, p10, p01, p00) {
  const n = p11 + p10 + p01 + p00;
  if (n === 0) return 0;
  const p1plus = p11 + p10;
  const pplus1 = p11 + p01;
  const p0plus = p01 + p00;
  const pplus0 = p10 + p00;
  const denom = Math.sqrt(p1plus * pplus1 * p0plus * pplus0);
  if (denom === 0) return 0;
  return (p11 * p00 - p10 * p01) / denom;
}

function hasMinimumObservations(sampleSize, minimum = 100) {
  return sampleSize >= minimum;
}

function calculateJuiceAdjustedEV(modelProb, stake = 110) {
  const payout = 100;
  return (modelProb * payout) - ((1 - modelProb) * stake);
}

module.exports = { phiCoefficient, hasMinimumObservations, calculateJuiceAdjustedEV };
