import { describe, it, expect } from 'vitest';
import { parseAsiBonuses, makeSkillResolver, parseBackgroundSkills, parseTraitSkills } from './origin';
import { getSystem } from '@/lib/rules';

const resolve = makeSkillResolver(getSystem('5e').skills);

describe('parseAsiBonuses', () => {
  it('parses a single ability increase', () => {
    expect(parseAsiBonuses('Your Dexterity score increases by 2.')).toEqual({ dex: 2 });
  });
  it('parses two abilities (Half-Orc)', () => {
    expect(parseAsiBonuses('Your Strength score increases by 2, and your Constitution score increases by 1.'))
      .toEqual({ str: 2, con: 1 });
  });
  it('parses Human "+1 to all"', () => {
    expect(parseAsiBonuses('Your ability scores each increase by 1.'))
      .toEqual({ str: 1, dex: 1, con: 1, int: 1, wis: 1, cha: 1 });
  });
  it('is empty for prose with no ASI', () => {
    expect(parseAsiBonuses('You have darkvision.')).toEqual({});
  });
});

describe('parseBackgroundSkills', () => {
  it('takes both fixed skills (Acolyte)', () => {
    expect(parseBackgroundSkills('Insight, Religion', resolve)).toEqual(['insight', 'religion']);
  });
  it('stops at a choose-one clause (Charlatan)', () => {
    expect(parseBackgroundSkills('Deception, and either Culture, Insight, or Sleight of Hand.', resolve)).toEqual(['deception']);
  });
  it('handles "plus your choice" (Crime Syndicate Member)', () => {
    expect(parseBackgroundSkills('Deception, plus your choice of one between Sleight of Hand or Stealth.', resolve)).toEqual(['deception']);
  });
});

describe('parseTraitSkills', () => {
  it('grants Perception from Elf Keen Senses', () => {
    expect(parseTraitSkills('Keen Senses. You have proficiency in the Perception skill.', resolve)).toEqual(['perception']);
  });
  it('grants Intimidation from Half-Orc Menacing', () => {
    expect(parseTraitSkills('Menacing. You gain proficiency in the Intimidation skill.', resolve)).toEqual(['intimidation']);
  });
});
