{
  "name": "upi_3way",
  "display_name": "UPI 3-Way Recon (Bank ↔ Gateway ↔ Internal System)",
  "description": "Replaces legacy types bank_upi_vs_momentspay + his_bank_upi + his_momentspay_upi. Stage 1 reproduces matchers/upi.py (single 4-key tier: VPA + terminal + amount + RRN padded to 12, no fallback — reference rule_engine id 4); stages 2–3 reproduce ids 5 and 17.",
  "stages": [
    {
      "stage": "bank_upi_vs_gateway",
      "display_name": "Bank UPI Settlement vs Gateway",
      "side_a": { "source": "template:bank_upi_settlement" },
      "side_b": {
        "source": "template:momentspay_gateway",
        "filters": [{ "field": "payment_mode", "op": "eq", "value": "UPI" }]
      },
      "tiers": [
        {
          "name": "exact-4key",
          "keys": [
            ["payer_vpa", "payer_vpa"],
            ["terminal_id", "terminal_id"],
            ["amount", "amount"],
            ["rrn", "rrn"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "BankUPI-GW-Matched",
        "unmatched_sheet": "BankUPI-GW-Unmatched",
        "unmatched_sheet_b": "GW-UPI-NoSettlement",
        "carry_fields": ["transaction_id", "processing_id", "email"]
      }
    },
    {
      "stage": "internal_vs_bank_upi",
      "display_name": "Internal System vs Matched Bank UPI",
      "side_a": {
        "source": "template:internal_billing_export",
        "filters": [{ "field": "payment_mode", "op": "eq", "value": "UPI" }]
      },
      "side_b": { "source": "stage:bank_upi_vs_gateway:matched" },
      "tiers": [
        {
          "name": "txnid-amount",
          "keys": [
            ["pg_transaction_id", "transaction_id"],
            ["amount", "amount"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "Internal-BankUPI-Matched",
        "unmatched_sheet": "Internal-BankUPI-Unmatched"
      }
    },
    {
      "stage": "internal_vs_gateway_upi",
      "display_name": "Internal System vs Gateway (UPI, direct)",
      "side_a": {
        "source": "template:internal_billing_export",
        "filters": [{ "field": "payment_mode", "op": "eq", "value": "UPI" }]
      },
      "side_b": {
        "source": "template:momentspay_gateway",
        "filters": [{ "field": "payment_mode", "op": "eq", "value": "UPI" }]
      },
      "tiers": [
        {
          "name": "txnid-amount",
          "keys": [
            ["pg_transaction_id", "transaction_id"],
            ["amount", "amount"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "Internal-GW-UPI-Matched",
        "unmatched_sheet": "Internal-GW-UPI-Unmatched"
      }
    }
  ],
  "report": {
    "location_summary": { "enabled": true, "group_by_field": "location" },
    "include_tier_breakdown": true
  }
}
