import { createQuery } from '@tanstack/svelte-query';
import { api } from './client';
import { qk } from './queries';
import type { ArtistSuggestion } from './types';

export async function listSuggestions(limit = 12): Promise<ArtistSuggestion[]> {
  return api.get<ArtistSuggestion[]>(`/api/discover/suggestions?limit=${limit}`);
}

export function createSuggestionsQuery(limit = 12) {
  return createQuery({
    queryKey: qk.suggestions(limit),
    queryFn: () => listSuggestions(limit),
    staleTime: 5 * 60_000   // 5 minutes — see M5c spec §5
  });
}
