"""Reproduce the two rankings in the synthetic retail teaching case."""
import json
from pathlib import Path

folder = Path(__file__).resolve().parent
case = json.loads((folder / "retail-input.json").read_text())
expected = json.loads((folder / "expected-output.json").read_text())
all_shops = {row["id"] for row in case["shops"]}
visible = {row["id"] for row in case["shops"] if row["shared_checkout"]}
supported = {row["id"] for row in case["shops"] if row["independent_platform_record"]}

def shortlist(arc_count):
    counts = {**case["other_supplier_counts"], "Arc": arc_count}
    return sorted(counts, key=lambda supplier: (-counts[supplier], supplier))[:3]

result = {
    "before": shortlist(len(visible | supported)),
    "after": shortlist(len(supported)),
    "arc_supported": len(supported),
    "arc_unresolved": len(all_shops - supported),
}
if result != expected:
    raise SystemExit(f"Fixture mismatch: {result}")
print(json.dumps(result, indent=2))
