{
  "name": "card_3way",
  "display_name": "Card 3-Way Recon (Bank ↔ Gateway ↔ Internal System)",
  "description": "Replaces legacy types bank_card_vs_momentspay + his_bank_card + his_momentspay_card. Stage 1 reproduces the 4-key→3-key cascade from matchers/card.py; stages 2–3 reproduce the chained HIS rules (reference rule_engine ids 1, 6, 11, 17) without hardcoding any business vocabulary.",
  "stages": [
    {
      "stage": "bank_card_vs_gateway",
      "display_name": "Bank Card Settlement vs Gateway",
      "side_a": { "source": "template:hdfc_card_mpr" },
      "side_b": {
        "source": "template:momentspay_gateway",
        "filters": [{ "field": "payment_mode", "op": "in", "values": ["CARD", "CREDIT CARD", "DEBIT CARD"] }]
      },
      "tiers": [
        {
          "name": "exact-4key",
          "keys": [
            ["card_last4", "card_last4"],
            ["terminal_id", "terminal_id"],
            ["amount", "amount"],
            ["approval_code", "approval_code"]
          ]
        },
        {
          "name": "3key",
          "keys": [
            ["card_last4", "card_last4"],
            ["terminal_id", "terminal_id"],
            ["amount", "amount"]
          ]
        },
        {
          "name": "tolerant",
          "enabled": false,
          "keys": [
            ["card_last4", "card_last4"],
            ["terminal_id", "terminal_id"]
          ],
          "amount_tolerance": { "type": "abs", "value": 1.0, "fields": ["amount", "amount"] },
          "date_window": { "days": 2, "fields": ["txn_date", "txn_date"] }
        }
      ],
      "output": {
        "matched_sheet": "BankCard-GW-Matched",
        "unmatched_sheet": "BankCard-GW-Unmatched",
        "unmatched_sheet_b": "GW-NoSettlement",
        "carry_fields": ["transaction_id", "processing_id", "email"]
      }
    },
    {
      "stage": "internal_vs_bank_card",
      "display_name": "Internal System vs Matched Bank Card",
      "side_a": {
        "source": "template:internal_billing_export",
        "filters": [{ "field": "payment_mode", "op": "in", "values": ["CARD", "CREDIT CARD", "DEBIT CARD"] }]
      },
      "side_b": { "source": "stage:bank_card_vs_gateway:matched" },
      "tiers": [
        {
          "name": "txnid-amount",
          "keys": [
            ["pg_transaction_id", "transaction_id"],
            ["amount", "amount"]
          ]
        },
        {
          "name": "manual-card",
          "keys": [
            ["card_last4", "card_last4"],
            ["amount", "amount"],
            ["approval_code", "approval_code"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "Internal-BankCard-Matched",
        "unmatched_sheet": "Internal-BankCard-Unmatched"
      }
    },
    {
      "stage": "internal_vs_gateway",
      "display_name": "Internal System vs Gateway (direct)",
      "side_a": { "source": "template:internal_billing_export" },
      "side_b": { "source": "template:momentspay_gateway" },
      "tiers": [
        {
          "name": "txnid-amount",
          "keys": [
            ["pg_transaction_id", "transaction_id"],
            ["amount", "amount"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "Internal-GW-Matched",
        "unmatched_sheet": "Internal-GW-Unmatched"
      }
    }
  ],
  "report": {
    "location_summary": { "enabled": true, "group_by_field": "location" },
    "include_tier_breakdown": true
  }
}
