/**
 * Friendships matter (T9): the weekly social pass now touches non-romantic
 * friend/family NPCs, not just the romantic partner.
 */
import { describe, it, expect } from 'vitest';
import { PlayerFactory } from '../../src/testing/PlayerFactory.js';
import { Person } from '../../src/models/Person.js';
import { processWeeklyFriendEvents } from '../../src/events/relationships/index.js';

function addFriendNpc(player: any, id: string, affinity = 50): Person {
  const friend = new Person({ id, firstname: 'Sam', lastname: 'Pal', sex: 'Female', status: 'alive', affinity } as never);
  friend.relationships = ['friend'];
  player.r.push(friend);
  return friend;
}

describe('processWeeklyFriendEvents', () => {
  it('moves a friend NPC affinity over many weeks (friends are no longer inert)', () => {
    const p: any = PlayerFactory.createAtAge(30);
    p.r = [];
    const friend = addFriendNpc(p, 'friend-1', 50);
    const start = friend.affinity;

    let fired = 0;
    for (let week = 0; week < 300; week++) {
      const events = processWeeklyFriendEvents(p);
      fired += events.length;
    }
    expect(fired).toBeGreaterThan(0);          // beats actually fire for friends
    expect(friend.affinity).not.toBe(start);   // and they move that NPC's affinity
    expect(friend.affinity).toBeGreaterThanOrEqual(-100);
    expect(friend.affinity).toBeLessThanOrEqual(100);
  });

  it('does nothing (no crash) when there is no social circle', () => {
    const p: any = PlayerFactory.createAtAge(30);
    p.r = [];
    expect(processWeeklyFriendEvents(p)).toEqual([]);
  });
});
