import click


def automatic_substitutions(user_information, players):
    """Formats automatic substitutions in a readable way."""
    substitution_ids = [(player["element_in"], player["element_out"])
                        for player in user_information["automatic_subs"]]

    substitutions = []
    for player_in_id, player_out_id in substitution_ids:
        player_in = [player for player in players
                     if player.player_id == player_in_id][0]
        player_out = [player for player in players
                      if player.player_id == player_out_id][0]

        substitutions.append("{} {} -> {} {}".format(
            player_out.gameweek_points,
            click.style(player_out.name, fg=player_out.colour),
            player_in.gameweek_points,
            click.style(player_in.name, fg=player_in.colour)))

    return ", ".join(substitutions)