import requests
from typing import Any


def tid_repo_prompt(image_data_url: str):

    """
    Prompt for TID repo image selection
    :param image_data_url: base url of the TID repo imaegs
    :return: download link of the image or None
    """

    entry_number: int = int(input("Please enter image number: ")) - 1

    try:
        response: requests.Response = requests.get(image_data_url)

    except Exception as error:
        print("[red]Perhaps you are not connected to the internet. Mind checking it again?")

    else:
        if not response.ok:
            print(f"[red]Oops, something went wrong {response.status_code}")
            return

        image_data: Any = response.json()

        if entry_number >= len(image_data):
            entry_number: int = 1

        file_name = image_data[entry_number]["image_name"]
        file_type = image_data[entry_number]["file_type"]
        return f"https://raw.githubusercontent.com/Muhimen123/TID/main/images/{file_name}.{file_type}"