const wageringCalculator = require('./wagering-calculator');

describe('wageringCalculator', () => {
  it('returns 0 when contribution is 0', () => {
    const result = wageringCalculator({
      depositAmount: 100,
      bonusAmount: 50,
      type: 'bonus',
      contribution: 0,
      rtp: 96,
      rolloverTerms: 20,
    });
    expect(result).toBe(0);
  });

  it('calculates correctly for bonus type', () => {
    const result = wageringCalculator({
      depositAmount: 100,
      bonusAmount: 50,
      type: 'bonus',
      contribution: 100,
      rtp: 96,
      rolloverTerms: 20,
    });
    // (50 * 20) / 1 = 1000, then 1000 / (96/100) = 1041.67
    expect(result).toBe(1041.67);
  });

  it('calculates correctly for bonus_deposit type', () => {
    const result = wageringCalculator({
      depositAmount: 100,
      bonusAmount: 50,
      type: 'bonus_deposit',
      contribution: 100,
      rtp: 96,
      rolloverTerms: 20,
    });
    // ((50 + 100) * 20) / 1 = 3000, then 3000 / (96/100) = 3125
    expect(result).toBe(3125);
  });

  it('returns originalAmount when rtp is 0', () => {
    const result = wageringCalculator({
      depositAmount: 100,
      bonusAmount: 50,
      type: 'bonus',
      contribution: 100,
      rtp: 0,
      rolloverTerms: 20,
    });
    // (50 * 20) / 1 = 1000, rtp is falsy so returns 1000
    expect(result).toBe(1000);
  });

  it('handles partial contribution percentage', () => {
    const result = wageringCalculator({
      depositAmount: 0,
      bonusAmount: 100,
      type: 'bonus',
      contribution: 50,
      rtp: 96,
      rolloverTerms: 30,
    });
    // (100 * 30) / 0.5 = 6000, then 6000 / (96/100) = 6250
    expect(result).toBe(6250);
  });
});
