from typing import Dict


def parse_image_loss(loss_config: Dict) -> Dict:
    """
    Parse the image loss part in loss configuration.

    :param loss_config: potentially outdated config
    :return: latest config
    """
    if "image" not in loss_config:
        # no image loss
        return loss_config

    if isinstance(loss_config["image"], list):
        # config up-to-date
        return loss_config

    image_loss_name = loss_config["image"]["name"]

    if image_loss_name not in loss_config["image"]:
        # config up-to-date
        return loss_config

    image_loss_config = {
        "name": image_loss_name,
        "weight": loss_config["image"].get("weight", 1.0),
    }
    image_loss_config.update(loss_config["image"][image_loss_name])
    loss_config["image"] = image_loss_config
    return loss_config