import { describe, it, expect } from 'vitest';
import { applyEventEffects } from '../../src/events/v2/engine/effects.js';

/**
 * Fix 0-C regression: generic `effects.stats` deltas must be clamped to the
 * centralized STAT_BOUNDS range at application time, not left unbounded until
 * the nightly clampPlayerStats pass. happiness/health/etc. are bounded 0..100.
 */
describe('applyEventEffects generic stat clamping (Fix 0-C)', () => {
  it('caps an out-of-range positive happiness delta at the max (100)', () => {
    const player = { c: { happiness: 50 } as Record<string, unknown> };
    applyEventEffects(player, { stats: { happiness: 200 } });
    expect(player.c.happiness).toBe(100);
  });

  it('floors an out-of-range negative happiness delta at the min (0)', () => {
    const player = { c: { happiness: 50 } as Record<string, unknown> };
    applyEventEffects(player, { stats: { happiness: -200 } });
    expect(player.c.happiness).toBe(0);
  });

  it('clamps health and stress to their bounds independently', () => {
    const player = { c: { health: 90, stress: 10 } as Record<string, unknown> };
    applyEventEffects(player, { stats: { health: 50, stress: -50 } });
    expect(player.c.health).toBe(100);
    expect(player.c.stress).toBe(0);
  });

  it('applies in-range deltas normally', () => {
    const player = { c: { happiness: 50 } as Record<string, unknown> };
    applyEventEffects(player, { stats: { happiness: 10 } });
    expect(player.c.happiness).toBe(60);
  });

  it('leaves unknown stat keys (not in STAT_BOUNDS) unclamped', () => {
    const player = { c: { reputation: 500 } as Record<string, unknown> };
    applyEventEffects(player, { stats: { reputation: 1000 } });
    // reputation is not in STAT_BOUNDS, so prior unclamped behavior is retained.
    expect(player.c.reputation).toBe(1500);
  });
});
