function calculateStraightPayout(amount, odds) { if (odds < 0) { return amount + (amount / (Math.abs(odds) / 100)); } return amount + (amount * (odds / 100)); } function calculateParlayPayout(amount, legsOdds) { let multiplier = 1; for (const odds of legsOdds) { if (odds < 0) { multiplier *= 1 + (100 / Math.abs(odds)); } else { multiplier *= 1 + (odds / 100); } } return amount * multiplier; } function calculatePayout(amount, betType, legsOdds) { if (!legsOdds || legsOdds.length === 0) return amount; if (betType === 'straight' || legsOdds.length === 1) { return Math.round(calculateStraightPayout(amount, legsOdds[0]) * 100) / 100; } // parlay, teaser, round_robin all use multiplied odds for MVP return Math.round(calculateParlayPayout(amount, legsOdds) * 100) / 100; } module.exports = { calculatePayout, calculateStraightPayout, calculateParlayPayout };