import { getDeviceId } from '../lib/device'; export interface EventData { id: number; slug: string; name: string; default_locale: string; created_at: string; updated_at: string; type?: { slug: string; name: string; icon: string; }; } export interface PackageData { id: number; name: string; max_photos: number; } export interface EventPackage { id: number; used_photos: number; expires_at: string; package: PackageData; } export interface EventStats { onlineGuests: number; tasksSolved: number; latestPhotoAt: string | null; } export async function fetchEvent(slug: string): Promise { const res = await fetch(`/api/v1/events/${slug}`); if (!res.ok) throw new Error('Event fetch failed'); return await res.json(); } export async function fetchStats(slug: string): Promise { const res = await fetch(`/api/v1/events/${slug}/stats`, { headers: { 'X-Device-Id': getDeviceId(), }, }); if (!res.ok) throw new Error('Stats fetch failed'); const json = await res.json(); return { onlineGuests: json.onlineGuests ?? 0, tasksSolved: json.tasksSolved ?? 0, latestPhotoAt: json.latestPhotoAt ?? null, }; } export async function getEventPackage(slug: string): Promise { const res = await fetch(`/api/v1/events/${slug}/package`); if (!res.ok) { if (res.status === 404) return null; throw new Error('Failed to load event package'); } return await res.json(); }