/**
 * PostHog event tracking — unit tests
 * Validates event names and payload shapes match the tracking plan.
 */

describe('PostHog Event Tracking', () => {
  const TRACKED_EVENTS = [
    'scan_completed',
    'grade_viewed',
    'upgrade_cta_clicked',
    'prop_shared',
    'alt_line_viewed',
  ];

  test('all 5 required events are defined', () => {
    expect(TRACKED_EVENTS).toHaveLength(5);
    expect(TRACKED_EVENTS).toContain('scan_completed');
    expect(TRACKED_EVENTS).toContain('grade_viewed');
    expect(TRACKED_EVENTS).toContain('upgrade_cta_clicked');
    expect(TRACKED_EVENTS).toContain('prop_shared');
    expect(TRACKED_EVENTS).toContain('alt_line_viewed');
  });

  test('scan_completed payload has required properties', () => {
    const payload = { player: 'LeBron James', stat: 'points', line: 25.5, grade: 'A' };
    expect(payload).toHaveProperty('player');
    expect(payload).toHaveProperty('stat');
    expect(payload).toHaveProperty('line');
    expect(payload).toHaveProperty('grade');
    expect(typeof payload.line).toBe('number');
  });

  test('grade_viewed payload has required properties', () => {
    const payload = { grade: 'B', tier: 'free' };
    expect(payload).toHaveProperty('grade');
    expect(payload).toHaveProperty('tier');
    expect(['free', 'analyst', 'desk']).toContain(payload.tier);
  });

  test('upgrade_cta_clicked payload has required properties', () => {
    const payload = { from_tier: 'free', trigger_location: 'scan_results' };
    expect(payload).toHaveProperty('from_tier');
    expect(payload).toHaveProperty('trigger_location');
  });

  test('prop_shared payload has required properties', () => {
    const payload = { platform: 'twitter', grade: 'A' };
    expect(payload).toHaveProperty('platform');
    expect(payload).toHaveProperty('grade');
  });

  test('alt_line_viewed payload has required properties', () => {
    const payload = { line: 24.5, edge: 3.2 };
    expect(payload).toHaveProperty('line');
    expect(payload).toHaveProperty('edge');
    expect(typeof payload.line).toBe('number');
    expect(typeof payload.edge).toBe('number');
  });
});
