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

import { dilemmaCatalog, resolveDilemmaChoice } from '../../../src/events/v2/catalog/dilemmas.js';

describe('events v2 dilemma catalog', () => {
  it('assigns stable ids and deterministic resolution text for each dilemma choice', () => {
    expect(dilemmaCatalog.length).toBeGreaterThan(0);

    for (const definition of dilemmaCatalog) {
      expect(definition.id).toMatch(/^[a-zA-Z][a-zA-Z0-9]+$/);
      expect(definition.choices.length).toBeGreaterThan(1);

      for (const choice of definition.choices) {
        const firstResolution = resolveDilemmaChoice(definition.id, choice.choiceId);
        const secondResolution = resolveDilemmaChoice(definition.id, choice.choiceId);
        expect(firstResolution).toBeTruthy();
        expect(firstResolution).toBe(secondResolution);
      }
    }
  });

  it('uses unique choiceId values inside each dilemma event', () => {
    for (const definition of dilemmaCatalog) {
      const choiceIds = definition.choices.map((choice) => choice.choiceId);
      const uniqueChoiceIds = new Set(choiceIds);
      expect(uniqueChoiceIds.size).toBe(choiceIds.length);
    }
  });
});
