import { apiGet } from './client';
import type { UnifiedSearchResponse } from '@/types';

export async function searchAll(
  query: string,
  opts: { deviceId?: string; limit?: number } = {},
): Promise<UnifiedSearchResponse> {
  try {
    const params = new URLSearchParams({ q: query });
    if (opts.deviceId) params.set('deviceId', opts.deviceId);
    if (opts.limit !== undefined) params.set('limit', String(opts.limit));
    return await apiGet<UnifiedSearchResponse>(`/my/search?${params}`);
  } catch (err) {
    throw err instanceof Error ? err : new Error('searchAll failed');
  }
}
