import requests


def fetch_chess_dotcom_games(user: str) -> list:
    """Uses the chess.com API to fetch the requested users games.

    Args:
        user: A chess.com username

    Returns:
        list: A list of all games for that user.
    """
    req = requests.get(f"https://api.chess.com/pub/player/{user}/games/archives")
    archive_urls = req.json()["archives"]
    games_list = []

    for url in archive_urls:
        archived_games = requests.get(url).json()["games"]

        for game in archived_games:
            games_list.append(game)

    print(f"INFO:    Imported {len(games_list)} games from chess.com")
    return games_list