import { describe, it, expect } from 'vitest';
import { enemyStatus, toPlayerEncounter } from './playerProjection';
import type { Combatant, Encounter } from '@/lib/schemas';

function mob(hp: { current: number; max: number }): Pick<Combatant, 'hp'> {
  return { hp: { ...hp, temp: 0 } };
}

describe('enemyStatus', () => {
  it('maps HP fraction to a masked band', () => {
    expect(enemyStatus(mob({ current: 20, max: 20 })).label).toBe('Healthy');
    expect(enemyStatus(mob({ current: 10, max: 20 })).label).toBe('Bloodied');
    expect(enemyStatus(mob({ current: 0, max: 20 })).label).toBe('Down');
  });
});

describe('toPlayerEncounter', () => {
  it('keeps PC HP but masks enemy HP as a status', () => {
    const e: Encounter = {
      id: 'e', campaignId: 'c', name: 'Fight', status: 'active', round: 2, turnIndex: 0,
      combatants: [
        { id: 'pc', name: 'Hero', kind: 'pc', initiative: 15, initBonus: 0, ac: 16, hp: { current: 9, max: 18, temp: 0 }, conditions: [], notes: '' },
        { id: 'm', name: 'Ogre', kind: 'monster', initiative: 8, initBonus: 0, ac: 13, hp: { current: 30, max: 60, temp: 0 }, conditions: [], notes: '' },
      ],
      log: [], createdAt: '', updatedAt: '',
    };
    const p = toPlayerEncounter(e);
    expect(p.combatants[0]).toMatchObject({ name: 'Hero', isCurrent: true, hp: { current: 9, max: 18 } });
    expect(p.combatants[0]!.status).toBeUndefined();
    expect(p.combatants[1]!.hp).toBeUndefined();
    expect(p.combatants[1]!.status?.label).toBe('Bloodied');
  });
});
