object @search

node :offset do
  @nextOffset
end

# node :page_count do |foo|
#   @search.page_count
# end

node :my_audio_latency do |user|
  current_user.last_jam_audio_latency.round if current_user.last_jam_audio_latency
end
                
node :filter_json do |foo|
  @search.to_json
end

# node :description do |foo|
#   @search.description
# end

node :is_blank_filter do |foo|
  @search.is_blank?
end
        
child(:results => :musicians) {
    attributes :id, :first_name, :last_name, :name, :city, :state, :country, :online, :musician, :photo_url, :biography, :regionname, :score, :full_score, :is_friend, :is_following, :pending_friend_request, :last_active_timestamp

    # node :is_friend do |musician|
    #   @search.is_friend?(musician)
    # end

    # node :is_following do |musician|
    #   @search.is_follower?(musician)
    # end

    # node :pending_friend_request do |musician|
    #   musician.pending_friend_request?(current_user)
    # end

    node :biography do |musician|
      musician.biography.nil? ? "" : musician.biography
    end

    child :musician_instruments => :instruments do
      attributes :instrument_id, :description, :proficiency_level, :priority
    end
    
    # child :top_followings => :followings do |uf|
    #   node :user_id do |uu| uu.id end
    #   node :photo_url do |uu| uu.photo_url end
    #   node :name do |uu| uu.name end
    # end

    # node :friend_count do |musician| @search.friend_count(musician) end
    # node :follow_count do |musician| @search.follow_count(musician) end
    # node :recording_count do |musician| @search.record_count(musician) end
    # node :session_count do |musician| @search.session_count(musician) end

    node :audio_latency do |musician|
      last_jam_audio_latency(musician)
    end

    node :latency_data do |musician|
      
      if latency = @latency_data.detect{|l_data| l_data[:user_id] == musician.id }
          audio_latency     = latency[:audio_latency].to_i
          internet_latency  = latency[:ars_internet_latency].to_i
          total_letency     = latency[:ars_total_latency]
          #sometimes neo4j returns 0 for audio latency. this is not correct. 
          #when this happens as a temporary hack we default audio latency to 5. 
          if audio_latency <= 0  
            audio_latency = 5 
            total_letency = audio_latency + internet_latency
          end
        { 
          audio_latency: audio_latency,
          ars_internet_latency: internet_latency,
          ars_total_latency: total_letency
        }
      end if @latency_data
    end

    # node :last_active_timestamp do |musician|
    #   if musician.updated_at || musician.last_jam_updated_at
    #     [musician.updated_at, musician.last_jam_updated_at].compact.max.to_i
    #   end
    # end

    child :genres => :genres do
      attributes :genre_id, :description
    end
}