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

import type { VersionPlan } from './version-plan';
import * as workActivityFactory from './work-activity-factory';

function plan(patch: Partial<VersionPlan> = {}): VersionPlan {
  return {
    id: 'plan-1',
    versionId: 'version-1',
    type: 'research',
    title: '支付链路调研',
    owner: 'PM',
    startTime: '2026-06-30T09:00',
    endTime: '2026-06-30T18:00',
    status: 'in_progress',
    createdAt: '2026-06-30',
    addedBy: 'PM',
    ...patch,
  };
}

test('makeVersionPlanResearchDirectionProgressActivity records direction progress details', () => {
  const makeVersionPlanResearchDirectionProgressActivity = (workActivityFactory as any).makeVersionPlanResearchDirectionProgressActivity as undefined | Function;
  assert.equal(typeof makeVersionPlanResearchDirectionProgressActivity, 'function');

  const activity = makeVersionPlanResearchDirectionProgressActivity!(plan(), {
    id: 'log-1',
    type: 'research_direction_progress',
    createdAt: '2026-06-30T10:00:00.000Z',
    actor: 'PM',
    title: '竞品分析更新为部分完成',
    directionTaskId: 'task-1',
    directionTitle: '竞品分析',
    coverageStatus: 'partial',
    completedContent: '完成登录流程对比',
    remainingContent: '补充支付流程差异',
    workStartedAt: '2026-06-30T09:30:00.000Z',
  });

  assert.equal(activity?.action, 'version_plan_research_direction_progress');
  assert.equal(activity?.category, 'progress');
  assert.equal(activity?.sourceType, 'version_plan');
  assert.equal(activity?.sourceId, 'plan-1');
  assert.equal(activity?.occurredAt, '2026-06-30T10:00:00.000Z');
  assert.equal(activity?.summary, '推进调研方向：竞品分析（部分完成）');
  assert.equal(activity?.metadata?.directionTaskId, 'task-1');
  assert.equal(activity?.metadata?.completedContent, '完成登录流程对比');
  assert.equal(activity?.metadata?.remainingContent, '补充支付流程差异');
  assert.equal(activity?.metadata?.workStartedAt, '2026-06-30T09:30:00.000Z');
});
