object @user_sync

glue :recorded_track do

  @object.current_user = current_user

  node :type do |i|
    'recorded_track'
  end

  attributes :id, :recording_id, :client_id, :track_id, :client_track_id, :md5, :length, :download_count, :instrument_id, :fully_uploaded, :upload_failures, :part_failures, :created_at

  node :user do |recorded_track|
    partial("api_users/show_minimal", :object => recorded_track.user)
  end

  node :recording do |recorded_track|
    partial("api_recordings/show", :object => recorded_track.recording)
  end

  node :upload do |recorded_track|
    {
      should_upload: true,
      too_many_upload_failures: recorded_track.too_many_upload_failures?
    }
  end

  node :download do |recorded_track|
    {
      should_download: recorded_track.can_download?(current_user),
      too_many_downloads: recorded_track.too_many_downloads?
    }
  end

end


glue :recorded_backing_track do

  @object.current_user = current_user

  node :type do |i|
    'recorded_backing_track'
  end

  attributes :id, :recording_id, :client_id, :track_id, :client_track_id, :md5, :length, :download_count, :fully_uploaded, :upload_failures, :part_failures, :created_at, :filename

  node :user do |recorded_backing_track|
    partial("api_users/show_minimal", :object => recorded_backing_track.user)
  end

  node :recording do |recorded_backing_track|
    partial("api_recordings/show", :object => recorded_backing_track.recording)
  end

  node :mine do |recorded_backing_track|
    recorded_backing_track.user == current_user
  end

  node :upload do |recorded_backing_track|
    {
      should_upload: true,
      too_many_upload_failures: recorded_backing_track.too_many_upload_failures?
    }
  end

  node :download do |recorded_backing_track|
    {
      should_download: recorded_backing_track.can_download?(current_user),
      too_many_downloads: recorded_backing_track.too_many_downloads?
    }
  end

end

glue :mix do

  @object.current_user = current_user

  node :type do |i|
    'mix'
  end

  attributes :id, :recording_id, :started_at, :completed_at, :completed, :should_retry, :download_count, :state

  node :recording do |mix|
    partial("api_recordings/show", :object => mix.recording)
  end

  node do |mix|
    {
      duration: mix.recording.duration,
      error: mix.error
    }
  end

  node :download do |mix|
    {
      should_download: mix.can_download?(current_user),
      too_many_downloads: mix.too_many_downloads?
    }
  end

end


glue :quick_mix do

  @object.current_user = current_user

  node :type do |i|
    'stream_mix'
  end

  attributes :id, :recording_id, :fully_uploaded, :upload_failures, :part_failures, :created_at

  node :user do |quick_mix|
    partial("api_users/show_minimal", :object => quick_mix.user)
  end

  node :recording do |quick_mix|
    partial("api_recordings/show", :object => quick_mix.recording)
  end


  node :upload do |quick_mix|
    {
      should_upload: true,
      too_many_upload_failures: quick_mix.too_many_upload_failures?
    }
  end

  node :download do |quick_mix|
    {
      should_download: false,
      too_many_downloads: false
    }
  end

end

