import { describe, it, expect } from 'vitest';
import { RecordEngagementInputViewModel } from './RecordEngagementInputViewModel';

describe('RecordEngagementInputViewModel', () => {
  it('maps basic fields from input data', () => {
    const vm = new RecordEngagementInputViewModel({
      eventType: 'button_click',
      userId: 'user-1',
      metadata: { key: 'value' },
    });

    expect(vm.eventType).toBe('button_click');
    expect(vm.userId).toBe('user-1');
    expect(vm.metadata).toEqual({ key: 'value' });
  });

  it('derives displayEventType from snake_case eventType', () => {
    const vm = new RecordEngagementInputViewModel({
      eventType: 'page_view',
    });

    expect(vm.displayEventType).toBe('Page View');
  });

  it('detects presence of metadata and counts keys', () => {
    const withMetadata = new RecordEngagementInputViewModel({
      eventType: 'test',
      metadata: { a: 1, b: 2 },
    });
    const withoutMetadata = new RecordEngagementInputViewModel({
      eventType: 'test',
    });
    const emptyMetadata = new RecordEngagementInputViewModel({
      eventType: 'test',
      metadata: {},
    });

    expect(withMetadata.hasMetadata).toBe(true);
    expect(withMetadata.metadataKeysCount).toBe(2);

    expect(withoutMetadata.hasMetadata).toBe(false);
    expect(withoutMetadata.metadataKeysCount).toBe(0);

    expect(emptyMetadata.hasMetadata).toBe(false);
    expect(emptyMetadata.metadataKeysCount).toBe(0);
  });
});
