#!/usr/bin/env python3
"""Checks for relocate_stopped_host.sh: directory overlap before, store identity after."""
import json
import sys
from pathlib import Path


def paths(values):
    resolved = [Path(value).resolve() for value in values]
    assert resolved[0].is_dir(), "Existing host directory required"
    for index, left in enumerate(resolved):
        for right in resolved[index + 1:]:
            assert left != right and left not in right.parents and right not in left.parents, \
                "Host, destination and evidence directories must not overlap"


def identity(evidence):
    root = Path(evidence)
    export = json.loads((root / "export.json").read_text())
    restored = json.loads((root / "import.json").read_text())
    assert export["exported"] is True and restored["imported"] is True
    assert export["store_uuid"] == restored["store_uuid"]
    assert export["export_id"] == restored["export_id"]
    print("IMPORT original store/export identity; selected receipt page unchanged")
    print("SOURCE retired; review restored cancellation, revocation and outstanding operations before serving")


if __name__ == "__main__":
    command, *arguments = sys.argv[1:]
    {"paths": paths, "identity": lambda values: identity(*values)}[command](arguments)
