# ═════════════════════════════════════════════════════════════════
# 借款合同 · 回归测试用例
# ═════════════════════════════════════════════════════════════════
# 配套文件：contract_loan.yaml
# 重点展示：multi_entity / derived fields / external 数据源 mock

target: contract_loan.yaml

# 外部数据源的 mock 值（替代真实 API 调用）
external_mocks:
  lpr_lookup:
    "1y": 0.0345                  # 当前 1 年 LPR = 3.45%
    # 推导：LPR_4x = 0.0345 * 4 = 0.138

fixtures:

  # ═════════════════════════════════════════════════════════════
  # JK-001 · 借款主体合法性
  # ═════════════════════════════════════════════════════════════
  JK-001:
    - name: 已执行-借贷双方合法
      phase: executed
      extract:
        借款人姓名: 张三
        借款人身份证: "110101197001011234"
        出借人姓名: 李四
        出借人身份证: "310102198505051234"
      expected: pass

    - name: 已执行-借款人身份证校验失败
      phase: executed
      extract:
        借款人姓名: 张三
        借款人身份证: "110101197001011230"    # 末位错
        出借人姓名: 李四
        出借人身份证: "310102198505051234"
      expected: fail

    - name: 草稿-只有姓名
      phase: draft
      extract:
        借款人姓名: 张三
        出借人姓名: 李四
      expected: pass                            # 草稿阶段身份证待补

  # ═════════════════════════════════════════════════════════════
  # JK-002 · 利率不超过 LPR × 4（核心规则）
  # 依赖 external.lpr_lookup mock：LPR_4x = 0.138
  # ═════════════════════════════════════════════════════════════
  JK-002:
    - name: 年利率 10% 合规
      phase: executed
      extract:
        年利率: 0.10
        # derived.LPR_4x = 0.138（mock 值）
      expected: pass

    - name: 年利率 20% 超限
      phase: executed
      extract:
        年利率: 0.20
      expected: fail

    - name: 年利率正好等于 LPR×4（边界）
      phase: executed
      extract:
        年利率: 0.138
      expected: fail                             # money.lt 严格小于

    - name: 年利率 0.137 边界内
      phase: executed
      extract:
        年利率: 0.137
      expected: pass

  # ═════════════════════════════════════════════════════════════
  # JK-003 · 所有担保人身份合法（multi-entity 核心测试）
  # ═════════════════════════════════════════════════════════════
  JK-003:
    - name: 三担保人全合法
      phase: executed
      extract:
        担保人:
          - {姓名: 张三, 身份证号: "110101197001011234", 担保金额: 500000, 担保方式: 连带责任保证}
          - {姓名: 李四, 身份证号: "310102198505051234", 担保金额: 800000, 担保方式: 连带责任保证}
          - {姓名: 王五, 身份证号: "440103199212121234", 担保金额: 300000, 担保方式: 一般保证}
      expected: pass

    - name: 第二个担保人身份证校验失败
      phase: executed
      extract:
        担保人:
          - {姓名: 张三, 身份证号: "110101197001011234", 担保金额: 500000, 担保方式: 连带责任保证}
          - {姓名: 李四, 身份证号: "310102198505051230", 担保金额: 800000, 担保方式: 连带责任保证}   # 末位错
          - {姓名: 王五, 身份证号: "440103199212121234", 担保金额: 300000, 担保方式: 一般保证}
      expected: fail                             # [*] 遍历，任一失败整体 fail

    - name: 第一个担保人姓名缺失
      phase: executed
      extract:
        担保人:
          - {姓名: null, 身份证号: "110101197001011234", 担保金额: 500000, 担保方式: 连带责任保证}
          - {姓名: 李四, 身份证号: "310102198505051234", 担保金额: 800000, 担保方式: 连带责任保证}
      expected: fail

    - name: 无担保人（规则跳过）
      phase: executed
      extract:
        担保人: []
      expected: skipped                          # activate_if 条件不满足

  # ═════════════════════════════════════════════════════════════
  # JK-004 · 担保总额覆盖借款本金（sum_ge 聚合）
  # ═════════════════════════════════════════════════════════════
  JK-004:
    - name: 担保覆盖
      phase: executed
      extract:
        借款本金: 1500000
        担保人:
          - {姓名: 张三, 担保金额: 500000, 担保方式: 连带责任保证}
          - {姓名: 李四, 担保金额: 800000, 担保方式: 连带责任保证}
          - {姓名: 王五, 担保金额: 300000, 担保方式: 一般保证}
      # derived.担保总额 = 1600000 >= 借款本金 1500000
      expected: pass

    - name: 担保不足
      phase: executed
      extract:
        借款本金: 2000000
        担保人:
          - {姓名: 张三, 担保金额: 500000, 担保方式: 连带责任保证}
          - {姓名: 李四, 担保金额: 800000, 担保方式: 连带责任保证}
      # derived.担保总额 = 1300000 < 借款本金 2000000
      expected: fail

    - name: 担保恰好等于本金
      phase: executed
      extract:
        借款本金: 1000000
        担保人:
          - {姓名: 张三, 担保金额: 1000000, 担保方式: 连带责任保证}
      expected: pass

  # ═════════════════════════════════════════════════════════════
  # JK-005 · 禁止利滚利
  # ═════════════════════════════════════════════════════════════
  JK-005:
    - name: 正常违约条款
      phase: executed
      extract:
        违约责任: 借款人逾期还款的，按每日 0.05% 支付违约金，违约金不超过借款本金 30%
        借款用途: 企业日常经营周转
      expected: pass

    - name: 出现利滚利字样
      phase: executed
      extract:
        违约责任: 借款人违约的，利息计入本金后继续计息，利滚利
        借款用途: 企业日常经营周转
      expected: fail

    - name: 借款用途违法
      phase: executed
      extract:
        违约责任: 正常违约金条款
        借款用途: 用于赌博和非法经营活动
      expected: fail

    - name: 出现砍头息
      phase: executed
      extract:
        违约责任: 出借人有权预扣利息，砍头息为借款的 10%
        借款用途: 经营周转
      expected: fail

  # ═════════════════════════════════════════════════════════════
  # JK-006 · 违约金不超过 30%（ratio_within）
  # ═════════════════════════════════════════════════════════════
  JK-006:
    - name: 违约金 20%（合规）
      phase: executed
      extract:
        借款本金: 1000000
        违约金金额: 200000
      # derived.违约金比例 = 0.20
      expected: pass

    - name: 违约金 35%（超限）
      phase: executed
      extract:
        借款本金: 1000000
        违约金金额: 350000
      expected: fail

    - name: 违约金 30%（边界，恰好到上限）
      phase: executed
      extract:
        借款本金: 1000000
        违约金金额: 300000
      expected: pass                             # ratio_within max=0.30 是闭区间

  # ═════════════════════════════════════════════════════════════
  # JK-007 · 借款本金大小写一致性
  # ═════════════════════════════════════════════════════════════
  JK-007:
    - name: 大小写一致
      phase: executed
      extract:
        借款本金: 1000000
        借款本金大写: 壹佰万元整
      expected: pass

    - name: 大小写不一致
      phase: executed
      extract:
        借款本金: 1000000
        借款本金大写: 壹拾万元整                 # 差一位
      expected: fail

  # ═════════════════════════════════════════════════════════════
  # JK-008 · 借款期限合理性（带 depends_on）
  # ═════════════════════════════════════════════════════════════
  JK-008:
    - name: 正常期限
      phase: executed
      extract:
        借款人姓名: 张三
        借款人身份证: "110101197001011234"
        出借人姓名: 李四
        出借人身份证: "310102198505051234"
        借款日期: "2024-01-01"
        还款日期: "2025-01-01"
        签订日期: "2024-01-01"
      expected: pass

    - name: 借款日期晚于还款日期
      phase: executed
      extract:
        借款人姓名: 张三
        借款人身份证: "110101197001011234"
        出借人姓名: 李四
        出借人身份证: "310102198505051234"
        借款日期: "2024-06-01"
        还款日期: "2024-01-01"                   # ← 颠倒
        签订日期: "2024-01-01"
      expected: fail

    - name: 依赖规则失败时本规则被跳过
      phase: executed
      extract:
        借款人姓名: 张三
        借款人身份证: "110101197001011230"       # JK-001 会失败
        出借人姓名: 李四
        出借人身份证: "310102198505051234"
        借款日期: "2024-01-01"
        还款日期: "2025-01-01"
      expected: skipped_dependency               # JK-001 失败 → 本规则跳过

  # ═════════════════════════════════════════════════════════════
  # JK-SEAL-001 · 双方签章
  # ═════════════════════════════════════════════════════════════
  JK-SEAL-001:
    - name: 双方签章齐全
      phase: executed
      extract:
        借款人姓名: 张三
        出借人姓名: 李四
      visual_manifest:
        seals:
          - id: 借款人签章
            detection_score: 0.94
            ocr_text: 张三
          - id: 出借人签章
            detection_score: 0.92
            ocr_text: 李四
      expected: pass

    - name: 缺出借人签章
      phase: executed
      extract:
        借款人姓名: 张三
        出借人姓名: 李四
      visual_manifest:
        seals:
          - id: 借款人签章
            detection_score: 0.94
            ocr_text: 张三
      expected: fail

    - name: 草稿阶段无签章（规则跳过）
      phase: draft
      extract:
        借款人姓名: 张三
        出借人姓名: 李四
      visual_manifest:
        seals: []
      expected: skipped_phase

  # ═════════════════════════════════════════════════════════════
  # JK-GROUP-INTEREST · 利率合规总判定（规则组）
  # ═════════════════════════════════════════════════════════════
  JK-GROUP-INTEREST:
    - name: 全部子规则通过
      phase: executed
      extract:
        年利率: 0.10
        违约责任: 正常违约金条款
        借款用途: 经营周转
        借款本金: 1000000
        违约金金额: 200000
      expected: pass

    - name: 子规则 JK-002 失败导致组失败
      phase: executed
      extract:
        年利率: 0.25                             # 超限
        违约责任: 正常违约金条款
        借款用途: 经营周转
        借款本金: 1000000
        违约金金额: 200000
      expected: fail
