module GameHelpers
  def setup_game
    # Default game has 4 players
    game = FactoryGirl.create :game
    user1 = FactoryGirl.create :user
    user2 = FactoryGirl.create :user
    user3 = FactoryGirl.create :user
    user4 = FactoryGirl.create :user
    game.seats[0].sit user1
    game.seats[1].sit user2
    game.seats[2].sit user3
    game.seats[3].sit user4
    game.start
    return game
  end

  def setup_visitor_game
    # Default game has 3 players
    game = FactoryGirl.create :game

    u = FactoryGirl.build :user
    game.seats[0].sit u

    u = FactoryGirl.build :user
    game.seats[1].sit u

    u = FactoryGirl.build :user
    game.seats[2].sit u

    return game
  end

  def find_card card
    find("[data-card-name='#{card.to_s}'] ~ img")
  end

  def cards_to_beat
    @cards = find("#cards-to-beat")
    if @cards
      @cards = @cards.find_all('img')
    end
    @array = []
    @cards.map {|c| @array << c[:alt]}
    return @array.join " "
  end
end

module Features
  #DEPRECATED Features module. Use top level GameHelpers
  module GameHelpers
    def setup_game
      # Default game has 4 players
      game = FactoryGirl.create :game
      user1 = FactoryGirl.create :user
      user2 = FactoryGirl.create :user
      user3 = FactoryGirl.create :user
      user4 = FactoryGirl.create :user
      game.seats[0].sit user1
      game.seats[1].sit user2
      game.seats[2].sit user3
      game.seats[3].sit user4
      game.start
      return game
    end

    def setup_visitor_game
      # Default game has 3 players
      game = FactoryGirl.create :game

      u = FactoryGirl.build :user
      game.seats[0].sit u

      u = FactoryGirl.build :user
      game.seats[1].sit u

      u = FactoryGirl.build :user
      game.seats[2].sit u

      return game
    end

    def find_card card
      find("[data-card-name='#{card.to_s}'] ~ img")
    end

    def cards_to_beat
      @cards = find("#cards-to-beat")
      if @cards
        @cards = @cards.find_all('img')
      end
      @array = []
      @cards.map {|c| @array << c[:alt]}
      return @array.join " "
    end
  end
end

# DEPRECATED Models module. Use top level GameHelpers
# TODO: DRY up this repetition
module Models
  module GameHelpers
    def setup_game
      # Default game has 4 players
      game = FactoryGirl.create :game
      user1 = FactoryGirl.create :user
      user2 = FactoryGirl.create :user
      user3 = FactoryGirl.create :user
      user4 = FactoryGirl.create :user
      game.seats[0].sit user1
      game.seats[1].sit user2
      game.seats[2].sit user3
      game.seats[3].sit user4
      game.start
      return game
    end
  end
end
