json.extract! @game, :id, :title, :created_at, :updated_at, :controlling_player_id
if  @game.controlling_player_id == @game.player_to_beat.try(:id)
  json.play_to_beat_string "None"
  json.cards_to_beat []
else
  json.play_to_beat_string @game.play_to_beat.try(:play).try(:to_s)
  json.cards_to_beat @game.play_to_beat.try(:play).try(:player_cards)
end

json.winner_player_id @game.winner_player_id

json.is_joinable @game.joinable?(current_user)
json.is_started !@game.status.nil?
json.is_startable @game.startable?
json.current_user_id current_user.try(:id)
json.current_user_soft_token current_user.try(:soft_token)

#json.players @game.players do |player|
#  json.id player.id
#  json.email player.user.try(:email)
#  json.inventory_count player.inventory.count
#  json.user_id player.user.try(:id)
#  json.soft_token player.soft_token
#
#  if player.soft_token == current_user.soft_token
#    json.inventory player.inventory
#  end
#end

json.seats @game.seats.order(:position) do |seat|
  json.id seat.id
  json.table_id seat.table_id
  json.position seat.position
  json.user_id seat.user_id
  json.user_soft_token seat.user_soft_token
  json.user_display_name seat.user_display_name

  json.set! :player do
    @player = nil
    if !seat.user_id.blank?
      @player = @game.players.find_by(user_id: seat.user_id)
    elsif !seat.user_soft_token.blank?
      @player = @game.players.find_by(soft_token: seat.user_soft_token)
    end
    if @player
      json.id @player.id
      json.email @player.user.try(:email)
      json.inventory_count @player.inventory.count
      json.user_id @player.user_id
      json.soft_token @player.soft_token
      json.inventory @player.inventory if @player.soft_token == current_user.soft_token
    end
  end
end
