import requests


def fetch_image(session: requests.Session, folder, image):
    """Fetch an image from TibiaWiki and saves it the disk.

    Parameters
    ----------
    session: :class:`request.Session`
        The request session to use to fetch the image.
    folder: :class:`str`
        The folder where the images will be stored locally.
    image: :class:`WikiImage`
        The image data.

    Returns
    -------
    :class:`bytes`
        The bytes of the image.
    """
    r = session.get(image.file_url)
    r.raise_for_status()
    image_bytes = r.content
    with open(f"images/{folder}/{image.file_name}", "wb") as f:
        f.write(image_bytes)
    return image_bytes