#!/usr/bin/env python3
"""Runs on THIS host. Given generated_icons/manifest.json, computes which
installed override files should simply be DELETED on restore rather than
restored from backup: every path under the generic hicolor/breeze-dark
overlay (both the standard scalable+raster mirrors 11-deploy-icon-theme.sh
always writes, and any exact-path override that happens to land there too).

There's categorically no legitimate original to preserve at those paths --
the only real file for either theme is the root-owned system copy under
/usr/share/icons/, which this pipeline never touches; a live user-local
file at that path can only be this pipeline's own prior output, even if it
happened to exist (and so get backed up) before backup-before-overwrite
protection was added. Treating those backups as restorable would put back
an earlier generation's output instead of truly reverting. Restoring FROM
backup is reserved for every other theme (e.g. kora), where a real
pre-existing original could genuinely have been overwritten.

Prints the delete-list, one "theme/relpath" per line, to stdout. Recomputed
fresh every run -- no separate tracking state to keep in sync.
"""
import argparse
import json
from pathlib import Path

INSTALL_THEMES = ["hicolor", "breeze-dark"]
RASTER_SIZES = (48, 64, 128)


def standard_paths_for(name, is_status):
    contexts = ["apps"] + (["status"] if is_status else [])
    for theme in INSTALL_THEMES:
        for ctx in contexts:
            yield f"{theme}/scalable/{ctx}/{name}.svg"
            for size in RASTER_SIZES:
                yield f"{theme}/{size}x{size}/{ctx}/{name}.png"


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--manifest", required=True)
    args = ap.parse_args()

    manifest = json.loads(Path(args.manifest).read_text())

    to_delete = set()
    for name, entry in manifest.items():
        is_status = entry.get("is_status", False)
        to_delete.update(standard_paths_for(name, is_status))

        theme = entry.get("source_theme")
        relpath = entry.get("source_relpath")
        if theme in INSTALL_THEMES and relpath:
            to_delete.add(f"{theme}/{relpath}")

    for p in sorted(to_delete):
        print(p)


if __name__ == "__main__":
    main()
