# abstracts the idea of downloading / uploading files to JamKazam.
# Recordings, JamTracks, and Video are this

class ApiUserSyncsController < ApiController

  before_filter :api_signed_in_user, :except => [ ]
  before_filter :auth_user

  respond_to :json

  def log
    @log || Logging.logger[ApiUserSyncsController]
  end

  def show
    @user_sync = UserSync.show(params[:user_sync_id], current_user.id)

    if @user_sync.nil?
      raise ActiveRecord::RecordNotFound
    end

    render "api_user_syncs/show", :layout => nil
  end

  # returns all downloads and uploads for a user, meaning it should return:
  # all recorded_tracks (audio and video/soon)
  # all mixes
  # all jamtracks (soon)
  def index
    data = UserSync.index(
                      {user_id:current_user.id,
                       recording_id: params[:recording_id],
                      offset: params[:since],
                      limit: params[:limit]})



    @user_syncs = data[:query]
    @next = data[:next]
    render "api_user_syncs/index", :layout => nil
  end

  def deletables
    data = UserSync.deletables({user_id:current_user.id, recording_ids: params[:recording_ids]})
    render json: {recording_ids: data}, status: 200
  end
end
