import { useQuery } from '@tanstack/react-query';
import { getTracks } from '@/features/tracks/services/trackService';
import { useAuth } from '@/features/auth/hooks/useAuth';

export const LIBRARY_KEYS = {
  all: ['library'] as const,
  tracks: (userId?: string) =>
    [...LIBRARY_KEYS.all, 'tracks', { userId }] as const,
};

export function useMyTracks(page = 1, limit = 50) {
  const { user } = useAuth();

  return useQuery({
    queryKey: [...LIBRARY_KEYS.tracks(user?.id), { page, limit }],
    queryFn: () => getTracks({ userId: user?.id, page, limit }),
    enabled: !!user?.id,
    placeholderData: (previousData) => previousData,
  });
}
