"""Pure agreement status rules shared by API and tests.""" from typing import Any, Dict, List def agreement_status(subscriptions: List[Dict[str, Any]], changes: List[Dict[str, Any]]) -> str: change_statuses = {row.get("status") for row in changes} if change_statuses.intersection({"failed", "partially_applied"}): return "Kræver handling" if "pending" in change_statuses or "draft" in change_statuses: return "Ændring afventer" if change_statuses.intersection({"approved_scheduled", "applying"}): return "Planlagt ændring" statuses = [row.get("status") for row in subscriptions] if not statuses or all(status in {"cancelled", "expired"} for status in statuses): return "Afsluttet" live = [status for status in statuses if status not in {"cancelled", "expired"}] if live and all(status == "terminating" for status in live): return "Under opsigelse" if any(status in {"cancelled", "expired", "terminating"} for status in statuses): return "Delvist opsagt" if any(status == "paused" for status in statuses) and any(status == "active" for status in statuses): return "Delvist pauseret" if any(status == "active" for status in statuses): return "Aktiv" if statuses and all(status == "scheduled" for status in statuses): return "Planlagt" return "Kladde"