import { useContext } from 'react'
import { NetworkRequest, useNetwork } from '../components/useNetwork'
import { UserContext } from '../contexts/UserContext'
import { Playlist } from '../types/Playlist'

export interface PlaylistResponse {
  playlist: Playlist
}

export function usePlaylist(
  playlistId: string,
  onRetry?: () => void
): NetworkRequest<PlaylistResponse> {
  const user = useContext(UserContext)
  const path = `api/playlists/${playlistId}`
  return useNetwork<PlaylistResponse>(path, user, onRetry)
}
