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

import {
  buildExecutionPipeline,
  buildIssueDraft,
  type ExecutionItem,
} from '@/lib/execution-pipeline';

const baseItem: ExecutionItem = {
  id: 'item-1',
  productId: 'bytelyst',
  type: 'feature',
  status: 'open',
  priority: 'high',
  title: 'Add export pipeline',
  description: 'Users need CSV exports for reports.',
  labels: ['customer-request'],
  assignee: null,
  reportedBy: 'sam@example.com',
  source: 'user_submitted',
  visibility: 'public',
  voteCount: 12,
  commentCount: 3,
  targetRelease: null,
  createdAt: '2026-05-01T00:00:00Z',
  updatedAt: '2026-05-30T00:00:00Z',
};

describe('buildExecutionPipeline', () => {
  it('ranks public roadmap items by execution leverage', () => {
    const pipeline = buildExecutionPipeline([
      { ...baseItem, id: 'low', priority: 'low', voteCount: 1, commentCount: 0, title: 'Low' },
      { ...baseItem, id: 'critical', priority: 'critical', voteCount: 4, title: 'Critical' },
      { ...baseItem, id: 'active', status: 'in_progress', voteCount: 8, title: 'Active' },
    ]);

    expect(pipeline.nextUp[0].id).toBe('critical');
    expect(pipeline.inFlight[0].id).toBe('active');
    expect(pipeline.summary).toMatchObject({ ready: 2, inFlight: 1, done: 0 });
  });

  it('builds a copyable issue draft for implementation handoff', () => {
    const draft = buildIssueDraft(baseItem);

    expect(draft.title).toBe('[feature] Add export pipeline');
    expect(draft.body).toContain('Users need CSV exports for reports.');
    expect(draft.body).toContain('/status/item-1');
    expect(draft.labels).toContain('roadmap');
    expect(draft.labels).toContain('customer-request');
  });
});
