from __future__ import annotations import argparse import json from pathlib import Path def recommend(row: dict) -> dict: if not row["budget_complete"] or row["client_budget"] is None: return {"decision": "ABSTAIN", "calculated_margin_rate": None, "human_review_required": True} net = row["quoted_price"] * (1 - row["discount_rate"]) * (1 - row["commission_rate"]) costs = row["delivery_cost"] + row["operational_cost"] margin = (net - costs) / net if net else -1 decision = "ACCEPT" if margin >= row["target_margin_rate"] and row["quoted_price"] <= row["client_budget"] else "NEGOTIATE" if margin >= row["target_margin_rate"] * 0.8 and row["quoted_price"] <= row["client_budget"] * 1.1 else "ABSTAIN" return {"decision": decision, "calculated_margin_rate": round(margin, 6), "human_review_required": True} def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("record_json", type=Path) args = parser.parse_args() print(json.dumps(recommend(json.loads(args.record_json.read_text(encoding="utf-8"))), ensure_ascii=False, indent=2)) if __name__ == "__main__": main()