import { describe, expect, it } from 'vitest';
import type { TenantEvent } from '../../api';
import { buildEventListStats } from './eventListStats';

const baseEvent = (overrides: Partial<TenantEvent>): TenantEvent => ({
  id: overrides.id ?? 1,
  slug: overrides.slug ?? 'event',
  name: overrides.name ?? 'Event',
  event_date: overrides.event_date ?? null,
  status: overrides.status ?? 'published',
  settings: overrides.settings ?? {},
  tasks_count: overrides.tasks_count ?? 0,
  active_invites_count: overrides.active_invites_count ?? 0,
  total_invites_count: overrides.total_invites_count ?? 0,
  photo_count: overrides.photo_count ?? 0,
  likes_sum: overrides.likes_sum ?? 0,
  engagement_mode: overrides.engagement_mode ?? 'tasks',
  event_type_id: overrides.event_type_id ?? null,
  event_type: overrides.event_type ?? null,
});

describe('buildEventListStats', () => {
  it('uses active invite count when available', () => {
    const stats = buildEventListStats(
      baseEvent({ photo_count: 12, tasks_count: 4, active_invites_count: 9, total_invites_count: 20 }),
    );
    expect(stats).toEqual({ photos: 12, guests: 9, tasks: 4 });
  });

  it('falls back to total invite count when active is missing', () => {
    const event = {
      ...baseEvent({ photo_count: 3, total_invites_count: 6 }),
      active_invites_count: undefined,
    } as TenantEvent;
    const stats = buildEventListStats(event);
    expect(stats.guests).toBe(6);
  });
});
