import { apiGet } from './client';
import type { Photo, Album } from '@/types';

export async function fetchPhotos(limit = 100, since?: string, deviceId?: string): Promise<Photo[]> {
  try {
    const params = new URLSearchParams({ limit: String(limit) });
    if (since) params.set('since', since);
    if (deviceId) params.set('deviceId', deviceId);
    return await apiGet<Photo[]>(`/my/photos?${params}`);
  } catch (err) {
    throw err instanceof Error ? err : new Error('fetchPhotos failed');
  }
}

export async function fetchAlbums(deviceId: string): Promise<Album[]> {
  try {
    return await apiGet<Album[]>(`/my/photos/albums?deviceId=${encodeURIComponent(deviceId)}`);
  } catch (err) {
    throw err instanceof Error ? err : new Error('fetchAlbums failed');
  }
}
