import { describe, expect, it } from 'vitest';

import { createEventRegistry } from '../../src/events/v2/registry.js';
import type { EventDefinition } from '../../src/events/v2/types.js';

describe('events v2 registry', () => {
  it('builds registry for unique event ids', () => {
    const defs: EventDefinition[] = [
      {
        id: 'event_unique_1',
        category: 'test',
        prompt: 'Question 1',
        choices: [{ choiceId: 'choice_1', text: 'Answer 1' }],
      },
      {
        id: 'event_unique_2',
        category: 'test',
        prompt: 'Question 2',
        choices: [{ choiceId: 'choice_1', text: 'Answer 1' }],
      },
    ];

    const registry = createEventRegistry(defs);

    expect(registry.count()).toBe(2);
    expect(registry.get('event_unique_1')?.id).toBe('event_unique_1');
  });

  it('throws when duplicate ids are registered', () => {
    const defs: EventDefinition[] = [
      {
        id: 'duplicate_event',
        category: 'test',
        prompt: 'Question 1',
        choices: [{ choiceId: 'choice_1', text: 'Answer 1' }],
      },
      {
        id: 'duplicate_event',
        category: 'test',
        prompt: 'Question 2',
        choices: [{ choiceId: 'choice_2', text: 'Answer 2' }],
      },
    ];

    expect(() => createEventRegistry(defs)).toThrow(/duplicate_event/i);
  });
});
