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

export async function listArtistTracks(artistId: string): Promise<TrackRef[]> {
  return api.get<TrackRef[]>(`/api/artists/${artistId}/tracks`);
}

export function createArtistTracksQuery(artistId: string) {
  return createQuery({
    queryKey: qk.artistTracks(artistId),
    queryFn: () => listArtistTracks(artistId),
    enabled: artistId.length > 0
  });
}
