import { describe, it, expect } from 'vitest';
import { isPathbuilder, pathbuilderToCharacterFields } from './pathbuilder';
import { parseCharacterImport } from './character';

const file = {
  build: {
    name: 'Valeros', class: 'Fighter', level: 3, ancestry: 'Human', background: 'Soldier',
    abilities: { str: 18, dex: 14, con: 14, int: 10, wis: 12, cha: 10 },
    attributes: { ancestryhp: 8, classhp: 10, bonushp: 0, bonushpPerLevel: 0 },
    proficiencies: { perception: 4, fortitude: 4, reflex: 4, will: 2, athletics: 4, intimidation: 2 },
  },
};

describe('pathbuilder import', () => {
  it('detects and converts a build', () => {
    expect(isPathbuilder(file)).toBe(true);
    expect(isPathbuilder({ build: {} })).toBe(false);
    const f = pathbuilderToCharacterFields(file.build);
    expect(f.system).toBe('pf2e');
    expect(f.name).toBe('Valeros');
    expect(f.className).toBe('Fighter');
    expect(f.level).toBe(3);
    expect(f.abilities!.str).toBe(18);
    expect(f.hp!.max).toBe(44); // 8 ancestry + (10 class + 2 con)*3
    expect(f.saveRanks!.con).toBe('expert');
    expect(f.saveRanks!.wis).toBe('trained');
    expect(f.skillRanks!.athletics).toBe('expert');
    expect(f.perceptionRank).toBe('expert');
  });

  it('parseCharacterImport handles a Pathbuilder file end-to-end', () => {
    const c = parseCharacterImport(JSON.stringify(file), 'cmp1');
    expect(c.name).toBe('Valeros');
    expect(c.system).toBe('pf2e');
    expect(c.campaignId).toBe('cmp1');
    expect(c.hp.max).toBe(44);
  });
});
