/**
 * Friendships matter (T9): the weekly social pass now touches non-romantic
 * family NPCs (friend beats moved to the Friendship V2 manager to avoid
 * double-beating). T9 covers family/child/sibling/parent only.
 */
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 addFamilyNpc(player: any, id: string, affinity = 50): Person {
  // Use 'sibling' tag — T9 now covers family/child/sibling/parent only.
  // Friend tags moved to Friendship V2 (friendship_manager.ts).
  const npc = new Person({ id, firstname: 'Sam', lastname: 'Pal', sex: 'Female', status: 'alive', affinity } as never);
  npc.relationships = ['sibling'];
  player.r.push(npc);
  return npc;
}

describe('processWeeklyFriendEvents', () => {
  it('moves a family NPC affinity over many weeks (family NPCs are no longer inert)', () => {
    const p: any = PlayerFactory.createAtAge(30);
    p.r = [];
    const sibling = addFamilyNpc(p, 'sibling-1', 50);
    const start = sibling.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 family
    expect(sibling.affinity).not.toBe(start);   // and they move that NPC's affinity
    expect(sibling.affinity).toBeGreaterThanOrEqual(-100);
    expect(sibling.affinity).toBeLessThanOrEqual(100);
  });

  it('does not fire beats for friend-tagged NPCs (friend beats now live in V2)', () => {
    const p: any = PlayerFactory.createAtAge(30);
    p.r = [];
    const friendNpc = new Person({ id: 'friend-1', firstname: 'Chris', sex: 'Male', status: 'alive', affinity: 50 } as never);
    friendNpc.relationships = ['friend'];
    p.r.push(friendNpc);
    // 300 weeks — T9 no longer covers 'friend' so zero beats expected.
    let fired = 0;
    for (let week = 0; week < 300; week++) {
      fired += processWeeklyFriendEvents(p).length;
    }
    expect(fired).toBe(0);
  });

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