import { describe, expect, it } from 'bun:test';
import { buildTerminalResearchNoteSeed } from './terminalResearchNote';
import type { TerminalEntry } from '../types/terminal';

describe('buildTerminalResearchNoteSeed', () => {
  it('builds a note seed from the latest company panel context', () => {
    const history: TerminalEntry[] = [
      {
        id: 'command-1',
        type: 'command',
        content: '/search NVDA',
        timestamp: new Date('2026-04-09T10:00:00Z'),
      },
      {
        id: 'panel-1',
        type: 'panel',
        content: {
          type: 'company',
          data: {
            symbol: 'NVDA',
            name: 'NVIDIA',
            price: 900,
            change: 12,
            changePercent: 1.35,
            marketCap: 2_000_000_000_000,
            profile: {
              sector: 'Semiconductors',
              description: 'GPU leader.',
            },
          },
        },
        timestamp: new Date('2026-04-09T10:00:01Z'),
      },
    ];

    const seed = buildTerminalResearchNoteSeed(history);

    expect(seed?.ticker).toBe('NVDA');
    expect(seed?.rawText).toContain('Current terminal context: company snapshot for NVDA');
    expect(seed?.rawText).toContain('Source command: /search NVDA');
    expect(seed?.rawText).toContain('Analyst note:');
  });
});
