{
  "name": "sahyadri_full",
  "display_name": "Full Multi-Bank Recon (Sahyadri reference, 17 rules)",
  "description": "Paper validation: every rule from the reference rule_engine_instruction.txt (ids 1–17) expressed in the generic model. Stage slugs carry the reference rule id in a comment-style suffix. Notable translation choices: (a) reference 'manual' rules (9–12) are separate stages against the RAW source so they see rows the primary chain never saw — matching the reference semantics; (b) all the manual SQL preprocessing (LPAD, RIGHT(card,4), unit renames, quote stripping) lives in the templates' normalize steps, not here.",
  "stages": [
    {
      "stage": "hdfc_card_vs_gateway",
      "display_name": "HDFC Card vs Gateway (ref rule 1)",
      "side_a": { "source": "template:hdfc_card_mpr" },
      "side_b": { "source": "template:momentspay_gateway" },
      "tiers": [
        {
          "name": "exact-4key",
          "keys": [
            ["card_last4", "card_last4"],
            ["terminal_id", "terminal_id"],
            ["amount", "amount"],
            ["approval_code", "approval_code"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "HDFC-GW-Matched",
        "unmatched_sheet": "HDFC-GW-Unmatched",
        "carry_fields": ["transaction_id", "processing_id", "email"]
      }
    },
    {
      "stage": "axis_card_vs_gateway",
      "display_name": "Axis Card vs Gateway (ref rule 2)",
      "side_a": { "source": "template:axis_card_mpr" },
      "side_b": { "source": "template:momentspay_gateway" },
      "tiers": [
        {
          "name": "exact-4key",
          "keys": [
            ["card_last4", "card_last4"],
            ["terminal_id", "terminal_id"],
            ["amount", "amount"],
            ["approval_code", "approval_code"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "Axis-GW-Matched",
        "unmatched_sheet": "Axis-GW-Unmatched",
        "carry_fields": ["transaction_id", "processing_id", "email"]
      }
    },
    {
      "stage": "amex_vs_gateway",
      "display_name": "AMEX vs Gateway (ref rule 3)",
      "side_a": { "source": "template:amex_settlement" },
      "side_b": { "source": "template:momentspay_gateway" },
      "tiers": [
        {
          "name": "3key",
          "keys": [
            ["terminal_id", "terminal_id"],
            ["card_last4", "card_last4"],
            ["amount", "amount"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "Amex-GW-Matched",
        "unmatched_sheet": "Amex-GW-Unmatched",
        "carry_fields": ["transaction_id", "processing_id", "email"]
      }
    },
    {
      "stage": "bank_upi_vs_gateway",
      "display_name": "Bank UPI vs Gateway (ref rule 4)",
      "side_a": { "source": "template:bank_upi_settlement" },
      "side_b": { "source": "template:momentspay_gateway" },
      "tiers": [
        {
          "name": "exact-4key",
          "keys": [
            ["payer_vpa", "payer_vpa"],
            ["terminal_id", "terminal_id"],
            ["amount", "amount"],
            ["rrn", "rrn"]
          ]
        }
      ],
      "output": {
        "matched_sheet": "UPI-GW-Matched",
        "unmatched_sheet": "UPI-GW-Unmatched",
        "carry_fields": ["transaction_id", "processing_id", "email"]
      }
    },
    {
      "stage": "internal_vs_bank_upi",
      "display_name": "Internal vs Matched UPI (ref rule 5)",
      "side_a": { "source": "template:internal_billing_export" },
      "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-UPI-Matched", "unmatched_sheet": "Internal-UPI-Unmatched" }
    },
    {
      "stage": "internal_vs_hdfc",
      "display_name": "Internal vs Matched HDFC (ref rule 6)",
      "side_a": { "source": "template:internal_billing_export" },
      "side_b": { "source": "stage:hdfc_card_vs_gateway:matched" },
      "tiers": [
        { "name": "txnid-amount", "keys": [["pg_transaction_id", "transaction_id"], ["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Internal-HDFC-Matched", "unmatched_sheet": "Internal-HDFC-Unmatched" }
    },
    {
      "stage": "internal_vs_axis",
      "display_name": "Internal vs Matched Axis (ref rule 7)",
      "side_a": { "source": "template:internal_billing_export" },
      "side_b": { "source": "stage:axis_card_vs_gateway:matched" },
      "tiers": [
        { "name": "txnid-amount", "keys": [["pg_transaction_id", "transaction_id"], ["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Internal-Axis-Matched", "unmatched_sheet": "Internal-Axis-Unmatched" }
    },
    {
      "stage": "internal_vs_amex_matched",
      "display_name": "Internal vs Matched AMEX (ref rule 8)",
      "side_a": { "source": "template:internal_billing_export" },
      "side_b": { "source": "stage:amex_vs_gateway:matched" },
      "tiers": [
        { "name": "txnid-amount", "keys": [["pg_transaction_id", "transaction_id"], ["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Internal-Amex-Matched", "unmatched_sheet": "Internal-Amex-Unmatched" }
    },
    {
      "stage": "internal_vs_bank_upi_manual",
      "display_name": "Internal vs raw UPI, manual (ref rule 9)",
      "side_a": { "source": "stage:internal_vs_bank_upi:unmatched_a" },
      "side_b": { "source": "template:bank_upi_settlement" },
      "tiers": [
        { "name": "amount-only", "keys": [["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Manual-UPI-Matched", "unmatched_sheet": "Manual-UPI-Unmatched" }
    },
    {
      "stage": "internal_vs_axis_manual",
      "display_name": "Internal vs raw Axis, manual (ref rule 10)",
      "side_a": { "source": "stage:internal_vs_axis:unmatched_a" },
      "side_b": { "source": "template:axis_card_mpr" },
      "tiers": [
        { "name": "card-amount", "keys": [["card_last4", "card_last4"], ["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Manual-Axis-Matched", "unmatched_sheet": "Manual-Axis-Unmatched" }
    },
    {
      "stage": "internal_vs_hdfc_manual",
      "display_name": "Internal vs raw HDFC, manual (ref rule 11)",
      "side_a": { "source": "stage:internal_vs_hdfc:unmatched_a" },
      "side_b": { "source": "template:hdfc_card_mpr" },
      "tiers": [
        {
          "name": "card-amount-approval",
          "keys": [["card_last4", "card_last4"], ["amount", "amount"], ["approval_code", "approval_code"]]
        }
      ],
      "output": { "matched_sheet": "Manual-HDFC-Matched", "unmatched_sheet": "Manual-HDFC-Unmatched" }
    },
    {
      "stage": "internal_vs_amex_manual",
      "display_name": "Internal vs raw AMEX, manual (ref rule 12)",
      "side_a": { "source": "stage:internal_vs_amex_matched:unmatched_a" },
      "side_b": { "source": "template:amex_settlement" },
      "tiers": [
        { "name": "amount-card", "keys": [["amount", "amount"], ["card_last4", "card_last4"]] }
      ],
      "output": { "matched_sheet": "Manual-Amex-Matched", "unmatched_sheet": "Manual-Amex-Unmatched" }
    },
    {
      "stage": "pine_vs_bank_upi",
      "display_name": "Pine vs Bank UPI (ref rule 13)",
      "side_a": { "source": "template:pine_processor" },
      "side_b": { "source": "template:bank_upi_settlement" },
      "tiers": [
        { "name": "amount-rrn", "keys": [["amount", "amount"], ["rrn", "rrn"]] }
      ],
      "output": { "matched_sheet": "Pine-UPI-Matched", "unmatched_sheet": "Pine-UPI-Unmatched" }
    },
    {
      "stage": "pine_vs_hdfc",
      "display_name": "Pine vs HDFC Card (ref rule 14)",
      "side_a": { "source": "template:pine_processor" },
      "side_b": { "source": "template:hdfc_card_mpr" },
      "tiers": [
        { "name": "approval-amount", "keys": [["approval_code", "approval_code"], ["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Pine-HDFC-Matched", "unmatched_sheet": "Pine-HDFC-Unmatched" }
    },
    {
      "stage": "pine_vs_axis",
      "display_name": "Pine vs Axis Card (ref rule 15)",
      "side_a": { "source": "template:pine_processor" },
      "side_b": { "source": "template:axis_card_mpr" },
      "tiers": [
        { "name": "approval-amount", "keys": [["approval_code", "approval_code"], ["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Pine-Axis-Matched", "unmatched_sheet": "Pine-Axis-Unmatched" }
    },
    {
      "stage": "pine_vs_amex",
      "display_name": "Pine vs AMEX (ref rule 16)",
      "side_a": { "source": "template:pine_processor" },
      "side_b": { "source": "template:amex_settlement" },
      "tiers": [
        { "name": "tid-amount", "keys": [["terminal_id", "terminal_id"], ["amount", "amount"]] }
      ],
      "output": { "matched_sheet": "Pine-Amex-Matched", "unmatched_sheet": "Pine-Amex-Unmatched" }
    },
    {
      "stage": "internal_vs_gateway",
      "display_name": "Internal vs Gateway, direct (ref rule 17)",
      "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
  }
}
