import { describe, it, expect } from 'vitest';
import { Person } from '../../src/models/Person.js';
import { Player } from '../../src/models/Player.js';

describe('friendship persistence fields', () => {
  it('Person round-trips friendshipTier, lastFriendInteractionDay, lastHangOutDay through toJSON', () => {
    const p = new Person({ firstname: 'Ana', sex: 'female' } as any);
    p.friendshipTier = 'close';
    p.lastFriendInteractionDay = 1234;
    p.lastHangOutDay = 1230;

    const revived = new Person(p.toJSON() as any);
    expect(revived.friendshipTier).toBe('close');
    expect(revived.lastFriendInteractionDay).toBe(1234);
    expect(revived.lastHangOutDay).toBe(1230);
  });

  it('Person defaults the new fields to undefined (old saves unaffected)', () => {
    const p = new Person({ firstname: 'Bo', sex: 'male' } as any);
    expect(p.friendshipTier).toBeUndefined();
    expect(p.lastFriendInteractionDay).toBeUndefined();
    expect(p.lastHangOutDay).toBeUndefined();
  });

  it('Player round-trips lastFriendBailoutDay through toJSON', () => {
    const character = new Person({ id: 'char-bailout', firstname: 'Test' });
    const player = new Player({ userId: 'test-bailout', character });
    player.lastFriendBailoutDay = 5000;
    const json = player.toJSON() as any;
    expect(json.lastFriendBailoutDay).toBe(5000);

    const revived = new Player(json);
    expect(revived.lastFriendBailoutDay).toBe(5000);
  });
});
