object @user

attributes :id, :first_name, :last_name, :name, :city, :state, :country, :location, :online, :photo_url, :musician, :gender, :birth_date, :internet_service_provider, :friend_count, :liker_count, :like_count, :follower_count, :following_count, :admin,
:recording_count, :session_count, :biography, :favorite_count, :audio_latency, :upcoming_session_count, :age, :website, :skill_level, :reuse_card, :email_needs_verification, :is_a_teacher, :is_a_student, :is_onboarder, :timezone,
:use_video_conferencing_server

node :location do |user|
  if user.musician?
     user.location
  else
     user.online ? 'Online' : 'Offline'
  end
end


node :teacher do |user|
  if @show_teacher && user.teacher
      partial("api_teachers/detail", :object => user.teacher)
  end
end


if @show_profile
  node :profile do
    partial("api_users/profile_show", :object => @user)
  end
end

if @autologin
  node :autologin do
    true
  end
end

# give back more info if the user being fetched is yourself

if current_user && @user == current_user
  attributes :email, :original_fpfile, :cropped_fpfile, :crop_selection, :session_settings, :show_whats_next, :show_whats_next_count, :subscribe_email, :auth_twitter, :new_notifications, :sales_count, :reuse_card, :purchased_jamtracks_count, :first_downloaded_client_at, :created_at, :first_opened_jamtrack_web_player, :gifted_jamtracks, :has_redeemable_jamtrack, :remaining, :has_stored_credit_card?, :remaining_test_drives, :jamclass_credits,  :can_buy_test_drive?, :lesson_package_type_id, :school_id, :is_guitar_center_student?, :purchase_required, :lesson_package_needs_purchase_id

  node :owned_school_id do |user|
    user.owned_school.id if user.owned_school
  end

  node :owned_retailer_id do |user|
      user.owned_retailer.id if user.owned_retailer
    end

  child :user_authorizations => :user_authorizations do |auth|
    attributes :uid, :provider, :token_expiration
  end

  child :test_drive_package_choices do |choice|
    attributes :id
  end

  node :geoiplocation do |user|
    geoiplocation = current_user.geoiplocation
    geoiplocation.info if geoiplocation
  end

  node :show_free_jamtrack do |user|
    user.show_free_jamtrack?
  end

  node :show_jamtrack_guide do |user|
    !user.first_played_jamtrack_at && user.jam_track_rights.count > 0
  end

  node :mods do |user|
    user.mods_json
  end

  node :has_recurly_account do |user|
    user.recurly_code == user.id
  end

  node :is_affiliate_partner do |user|
    user.affiliate_partner.present?
  end

  node :affiliate_referral_count do |user|
    user.affiliate_partner.try(:referral_user_count)
  end

  node :affiliate_earnings do |user|
    user.affiliate_partner.try(:cumulative_earnings_in_cents)
  end

  if @show_student
    node :has_unprocessed_lesson do |user|
      !!LessonBooking.unprocessed(user).first
    end
  end


elsif current_user
  node :is_friend do |uu|
    current_user.friends?(uu)
  end
  node :is_following do |uu|
    current_user.following?(uu)
  end
  node :is_liking do |uu|
    current_user.likes?(uu)
  end
  node :pending_friend_request do |uu|
    current_user.pending_friend_request?(uu)
  end
  node :my_audio_latency do |user|
    current_user.last_jam_audio_latency.round if current_user.last_jam_audio_latency
  end
  node :internet_score do |user|
    current_user.score_info(user)
  end
  node :has_rated_student do |user|
    current_user.has_rated_student(user)
  end
  node :has_booked_test_drive_with_student do |user|
    user.has_booked_test_drive_with_student?(current_user)
  end

  node :same_school_with_student do |user|
      user.same_school_with_student?(current_user)
  end
end

child :friends => :friends do
  attributes :id, :first_name, :last_name, :name, :online, :photo_url
end

child :followings => :followings do
  attributes :type

  node :id do |f|
    f.followable.id
  end

  node :name do |f|
    f.followable.name
  end

  node :location do |f|
    f.followable.location
  end

  node :photo_url do |f|
    f.followable.photo_url
  end
end

child :band_musicians => :bands do
  attributes :id, :name, :admin, :photo_url, :logo_url

  child :genres => :genres do
    attributes :id, :description
    #partial('api_genres/index', :object => @user.bands.genres)
  end
end

child :musician_instruments => :instruments do
  attributes :description, :proficiency_level, :priority, :instrument_id
end

child :genres do
  attributes :description, :id
end

child :music_sessions => :sessions do
  attributes :id, :description, :musician_access, :approval_required, :fan_access
end

node :last_jam_audio_latency do |user|
  user.last_jam_audio_latency.round if user.last_jam_audio_latency
end

