import dataclasses


def make_filename(metadata: dict) -> str:
    """
    Make a filename from `metadata` that is returned by `download(onmemory=True)`.

    Parameters
    ----------
    metadata
        A metadata dictionary.

    Returns
    -------
    filename
        File name.
    """
    rect = metadata["rect"]
    args = dataclasses.asdict(rect)
    type = args["type"]
    if type == "warp":
        args["name"] = f'{args["name"]}_{metadata["visit"]:06d}'
    if type == "coadd/bg":
        args["type"] = "coadd+bg"

    name = args.pop("name")
    return name.format(**args) + ".fits"