from typing import Optional


def _rename_list(
    list1: list[str], method: str, list2: Optional[list[str]] = None
) -> list[str]:
    """Renames multiple list items following different methods.

    Method can be "consecutive" to rename identical consecutive items
    with increasing number or "fuse" to fuse with the second list (list2)

    Args:
        list1: List of strings to be renamed
        method: Type of renaming method. Can be "consecutive" to rename consecutive
            identical items as progressive values ("tree", "tree" will become
            "tree_0", "tree_1"); "fuse" to fuse with the values from list2.
            list2 must be of the same length as list1 while fusing.

    Returns:
        list of renamed values
    """
    last = None
    new_list = []
    count = 0
    if method == "consecutive":
        for item in list1:
            if item == last:
                count += 1
                new_list.append(item + "_" + str(count))
                last = item
            else:
                new_list.append(item + "_0")
                count = 0
                last = item

    elif method == "fuse" and list2 is not None:
        if len(list1) != len(list2):
            raise ValueError(
                ("Length of lists not equal:" f" {len(list1)} vs {len(list2)}")
            )
        new_list = [str(i1) + "_" + str(i2) for i1, i2 in zip(list1, list2)]
    else:
        raise ValueError("Unrecognized method or list2 unspecified")
    return new_list