from pathlib import Path


def completely_pruned(wkspace):
    """Determine which systematics are completely pruned.

    Parameters
    ----------
    wkspace : str or os.PathLike
        Path of TRExFitter workspace.

    Returns
    -------
    list(str)
        Names of all completely pruned systematics.

    """
    pairs = []
    with (Path(wkspace) / "PruningText.txt").open("r") as f:
        for line in f:
            if not line.startswith(" --->>"):
                continue
            sys, status = line.strip()[7:].split("      ")
            if status == "is not present":
                continue
            pairs.append((sys, status))

    unique = sorted(set([p[0] for p in pairs]))
    tests = {u: 0 for u in unique}
    for sys, status in pairs:
        k = 0
        if status == "is kept":
            k = 1
        elif status == "is shape only":
            k = 1
        elif status == "is norm only":
            k = 1
        tests[sys] += k

    return [k for k, v in tests.items() if v == 0]