// Converts a PlaylistTrack row into the minimal TrackRef shape used
// by play queues + track menus. Centralizes the mapping so server
// additions (new TrackRef fields) only update one site.
//
// Returns null when the upstream track has been removed (track_id
// is null on the playlist row); callers should filter nulls.

import type { PlaylistTrack, TrackRef } from '$lib/api/types';

export function playlistTrackToRef(row: PlaylistTrack): TrackRef | null {
  if (!row.track_id) return null;
  return {
    id: row.track_id,
    title: row.title,
    album_id: row.album_id ?? '',
    album_title: row.album_title,
    artist_id: row.artist_id ?? '',
    artist_name: row.artist_name,
    duration_sec: row.duration_sec,
    stream_url: row.stream_url ?? ''
  };
}
