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

import type { DevTask } from './dev-task';
import { needsDelayReason } from './dev-task-transitions';

function task(patch: Partial<DevTask> = {}): DevTask {
  return {
    id: 'task-1',
    taskNo: 'DEV-001',
    requirementId: 'req-1',
    title: '实现排班规则',
    categoryId: 'cat-frontend-interaction',
    assigneeId: 'Alice',
    priority: 'P2',
    expectedStartAt: '2026-06-29T01:00:00.000Z',
    expectedEndAt: '2026-06-29T10:00:00.000Z',
    status: 'todo',
    isBlocked: false,
    createdBy: 'PM',
    createdAt: '2026-06-29T00:00:00.000Z',
    updatedAt: '2026-06-29T00:00:00.000Z',
    ...patch,
  };
}

test('needsDelayReason does not require a reason before expected end time', () => {
  assert.equal(needsDelayReason(task(), new Date('2026-06-29T09:00:00.000Z')), false);
});

test('needsDelayReason requires a reason after expected end time for todo tasks', () => {
  assert.equal(needsDelayReason(task(), new Date('2026-06-29T10:01:00.000Z')), true);
});
