import { describe, it, expect } from 'vitest';
import { XpCalculator } from '@domain/services/XpCalculator';

describe('XpCalculator', () => {
  const calc = new XpCalculator();

  it('null target → not done, 0 seconds', () => {
    const r = calc.computeEta({ currentLevel: 1, target: null, gaugeLevels: {}, activeGauges: [] });
    expect(r.done).toBe(false);
    expect(r.seconds).toBe(0);
  });

  it('level already reached → done', () => {
    const r = calc.computeEta({ currentLevel: 100, target: 100, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
    expect(r.done).toBe(true);
  });

  it('level above target → done', () => {
    const r = calc.computeEta({ currentLevel: 150, target: 100, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
    expect(r.done).toBe(true);
  });

  it('needs mangeoire gauge', () => {
    const r = calc.computeEta({ currentLevel: 1, target: 100, gaugeLevels: {}, activeGauges: [] });
    expect(r.needsGauge).toBe('mangeoire');
    expect(r.seconds).toBe(Infinity);
  });

  it('computes seconds to level up', () => {
    const r = calc.computeEta({ currentLevel: 1, target: 10, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
    expect(r.done).toBe(false);
    expect(r.seconds).toBeGreaterThan(0);
    expect(r.seconds).toBeLessThan(Infinity);
  });

  it('regression: should NOT show ~23h for short XP gain', () => {
    // Bug v1.1.4: timer displayed ~23h instead of real time
    const r = calc.computeEta({ currentLevel: 1, target: 5, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
    expect(r.seconds).toBeLessThan(3600); // Must be under 1h
  });
});
