import test from 'node:test';
import assert from 'node:assert/strict';

import { resolveDecomposeDraftRequirementFields } from './ai-decompose-adoption';

const requirements = [
  { id: 'req-1', code: 'REQ001', title: '案例分享基础功能' },
  { id: 'req-2', code: 'REQ002', title: '排行榜' },
];

test('keeps prototype-only drafts out of formal requirements during adoption', () => {
  const result = resolveDecomposeDraftRequirementFields(
    {
      requirementName: '预入职人员支持',
      references: [{ type: 'prototype_note', id: 'QY0020', label: 'QY0020' }],
    },
    requirements,
  );

  assert.deepEqual(result, {
    requirementId: '',
    requirementName: '预入职人员支持',
  });
});

test('maps formal requirement references by code during adoption', () => {
  const result = resolveDecomposeDraftRequirementFields(
    {
      requirementName: '不应覆盖正式需求',
      references: [
        { type: 'requirement', id: 'REQ002', label: 'REQ002 排行榜' },
        { type: 'prototype_note', id: 'QY0030', label: 'QY0030' },
      ],
    },
    requirements,
  );

  assert.deepEqual(result, {
    requirementId: 'req-2',
    requirementName: undefined,
  });
});
