object @jam_track

attributes :id, :name, :description, :initial_play_silence, :original_artist, :version, :year, :duration, :allow_free, :original_artist_slug, :name_slug

child(:genres) {
  attributes :id, :description
}

node :jmep do |jam_track|
  jam_track.jmep_json ? jam_track.jmep_json : nil
end

node :can_download do |item|
  !!item.right_for_user(current_user, ShoppingCart::JAMTRACK_FULL)
end

child(:jam_track_tracks => :tracks) {

  attributes :id, :part, :instrument, :track_type, :position

  node do |track|
      {
        preview_mp3_url: track.preview_public_url('mp3'),
        preview_ogg_url: track.preview_public_url('ogg'),
        preview_aac_url: track.preview_public_url('aac')
      }
   end
}

node do |jam_track|
  right = jam_track.right_for_user(current_user)
  if right
    {
      jam_track_right_id: right.id,
      purchased_at: right.created_at.to_i,
      last_mixdown_id: right.last_mixdown_id,
      last_stem_id: right.last_stem_id
    }
  end
end

node :mixdowns do |jam_track|
  items = []
  jam_track.mixdowns_for_user(current_user).each do |mixdown|
    items << partial("api_jam_track_mixdowns/show", :object => mixdown)
  end
  items
end
