class EndTurn
  def initialize(game:, player:)
    @game = game
    @player = player
  end

  def call
    @game.update!(current_player: next_player)
  end

  private

  def game_players
    @game_players ||= @game.players.order(created_at: :asc)
  end

  def next_player
    game_players[next_player_index]
  end

  def next_player_index
    (game_players.index(@player) + 1) % game_players.count
  end
end
