import { describe, it, expect } from 'vitest';
import { HALL_PRESETS, getHallPreset, hallFromLabel, ALL_HALL_TYPES } from '../halls.js';

describe('HALL_PRESETS', () => {
  it('notelett has 6 halls', () => {
    expect(HALL_PRESETS.notelett.halls).toHaveLength(6);
    expect(HALL_PRESETS.notelett.halls).toContain('insights');
    expect(HALL_PRESETS.notelett.halls).not.toContain('errors');
  });

  it('mindlyst has 6 halls with patterns and emotions', () => {
    expect(HALL_PRESETS.mindlyst.halls).toHaveLength(6);
    expect(HALL_PRESETS.mindlyst.halls).toContain('patterns');
    expect(HALL_PRESETS.mindlyst.halls).toContain('emotions');
  });

  it('coding has 6 halls with errors and advice', () => {
    expect(HALL_PRESETS.coding.halls).toHaveLength(6);
    expect(HALL_PRESETS.coding.halls).toContain('errors');
    expect(HALL_PRESETS.coding.halls).toContain('advice');
  });
});

describe('getHallPreset', () => {
  it('returns preset by name', () => {
    expect(getHallPreset('notelett')?.name).toBe('NoteLett');
  });

  it('returns undefined for unknown preset', () => {
    expect(getHallPreset('nonexistent')).toBeUndefined();
  });
});

describe('hallFromLabel', () => {
  it('matches exact hall type', () => {
    expect(hallFromLabel('decisions')).toBe('decisions');
  });

  it('is case-insensitive', () => {
    expect(hallFromLabel('DECISIONS')).toBe('decisions');
  });

  it('matches singular form via synonym', () => {
    expect(hallFromLabel('decision')).toBe('decisions');
  });

  it('maps synonyms to halls', () => {
    expect(hallFromLabel('bug')).toBe('errors');
    expect(hallFromLabel('feeling')).toBe('emotions');
    expect(hallFromLabel('tip')).toBe('advice');
    expect(hallFromLabel('trend')).toBe('patterns');
    expect(hallFromLabel('fact')).toBe('discoveries');
  });

  it('respects allowedHalls filter', () => {
    // 'errors' is not in notelett preset
    expect(hallFromLabel('bug', HALL_PRESETS.notelett.halls)).toBeUndefined();
    // 'errors' is in coding preset
    expect(hallFromLabel('bug', HALL_PRESETS.coding.halls)).toBe('errors');
  });

  it('returns undefined for unrecognized label', () => {
    expect(hallFromLabel('xyzzy')).toBeUndefined();
  });

  it('trims whitespace', () => {
    expect(hallFromLabel('  events  ')).toBe('events');
  });
});

describe('ALL_HALL_TYPES', () => {
  it('has 9 total hall types', () => {
    expect(ALL_HALL_TYPES).toHaveLength(9);
  });
});
