/**
 * Economy depth (T6): savings are meaningful, the spending-habits lever works,
 * and retirement stops wages.
 */
import { describe, it, expect } from 'vitest';
import { computeWeeklyFinances } from '../../src/game/finance.js';

function worker(spendingHabits: string, occupation = 'work', salary = 4000): any {
  return { occupation, salary, spendingHabits, items: [], activities: [] };
}

describe('T6 economy', () => {
  it('a working career now banks a meaningful slice of surplus', () => {
    const f = computeWeeklyFinances(worker('normal'));
    // Normal banking is now 35% of positive surplus (was 10%).
    expect(f.surplus).toBeGreaterThan(0);
    expect(f.net).toBeCloseTo(f.surplus * 0.35, 4);
    expect(f.net).toBeGreaterThan(0);
  });

  it('the spending-habits lever changes net cashflow (frugal banks most)', () => {
    const frugal = computeWeeklyFinances(worker('frugal'));
    const normal = computeWeeklyFinances(worker('normal'));
    const extravagant = computeWeeklyFinances(worker('extravagant'));
    // Frugal both lowers expenses AND banks a higher fraction → strictly best net.
    expect(frugal.net).toBeGreaterThan(normal.net);
    expect(normal.net).toBeGreaterThan(extravagant.net);
  });

  it('retirement earns no income', () => {
    const retired = computeWeeklyFinances(worker('normal', 'retired', 4000));
    expect(retired.grossIncome).toBe(0);
    // Still owes the rent floor → net is the savings drawdown (<= 0).
    expect(retired.net).toBeLessThanOrEqual(0);
  });
});
