"""从已标注的证据位置演示金额角色选择；不假装正则或固定标注就是模型。"""
from decimal import Decimal

text = "订单 A100 原价 199 元，实付 179 元，已退 50 元，申请再退 129 元。"
# 这些角色与片段由作者标注。真实提取器可以是模型，但输出必须再核对。
annotations = [
    ("paid", "179"), ("already_refunded", "50"), ("requested", "129"),
]
records = []
for role, quote in annotations:
    # 本教学输入中各数值只出现一次；一般文本需要提取器提供精确位置。
    start = text.index(quote)
    records.append({"role": role, "start": start, "end": start + len(quote), "quote": quote})

for item in records:
    # 先检查切片一致；这只证明文字确实出现，不证明角色判断正确。
    if text[item["start"]:item["end"]] != item["quote"]:
        raise ValueError("证据位置与原文不一致")

requested = [item for item in records if item["role"] == "requested"]
if len(requested) != 1:
    raise ValueError("请求金额不唯一，需要澄清")
print("客户请求金额：", Decimal(requested[0]["quote"]))

# 后台事实单独给出，不能拿客户陈述充当账本。
ledger = {"paid": Decimal("179.00"), "refunded": Decimal("50.00")}
remaining = ledger["paid"] - ledger["refunded"]
print("账面剩余金额：", remaining)
# 数值相等仍不构成退款批准；资格、权限和状态还需业务流程核验。
