{
  "nodes": [
    {
      "type": "inputNode",
      "id": "input",
      "name": "request",
      "position": { "x": 100, "y": 200 }
    },
    {
      "type": "decisionTableNode",
      "id": "tierDiscount",
      "name": "TierDiscount",
      "position": { "x": 400, "y": 80 },
      "content": {
        "hitPolicy": "first",
        "inputs": [
          { "id": "i1", "name": "Customer Tier", "field": "customer.tier" },
          { "id": "i2", "name": "Years Active", "field": "customer.yearsActive" }
        ],
        "outputs": [
          { "id": "o1", "name": "Base Discount", "field": "discount" }
        ],
        "rules": [
          { "_id": "r1", "i1": "\"platinum\"", "i2": "", "o1": "0.20" },
          { "_id": "r2", "i1": "\"gold\"", "i2": ">= 3", "o1": "0.15" },
          { "_id": "r3", "i1": "\"gold\"", "i2": "< 3", "o1": "0.12" },
          { "_id": "r4", "i1": "\"silver\"", "i2": ">= 2", "o1": "0.10" },
          { "_id": "r5", "i1": "\"silver\"", "i2": "< 2", "o1": "0.08" },
          { "_id": "r6", "i1": "", "i2": "", "o1": "0.05" }
        ],
        "passThrough": true
      }
    },
    {
      "type": "decisionTableNode",
      "id": "volumeDiscount",
      "name": "VolumeDiscount",
      "position": { "x": 400, "y": 200 },
      "content": {
        "hitPolicy": "first",
        "inputs": [
          { "id": "i1", "name": "Item Count", "field": "order.itemCount" }
        ],
        "outputs": [
          { "id": "o1", "name": "Volume Discount", "field": "volumeDiscount" }
        ],
        "rules": [
          { "_id": "r1", "i1": ">= 50", "o1": "0.10" },
          { "_id": "r2", "i1": ">= 25", "o1": "0.07" },
          { "_id": "r3", "i1": ">= 10", "o1": "0.05" },
          { "_id": "r4", "i1": "", "o1": "0" }
        ],
        "passThrough": true
      }
    },
    {
      "type": "decisionTableNode",
      "id": "promoCode",
      "name": "PromoCode",
      "position": { "x": 400, "y": 320 },
      "content": {
        "hitPolicy": "first",
        "inputs": [
          { "id": "i1", "name": "Promo Code", "field": "promoCode" },
          { "id": "i2", "name": "Subtotal", "field": "order.subtotal" }
        ],
        "outputs": [
          { "id": "o1", "name": "Promo Discount", "field": "promoDiscount" },
          { "id": "o2", "name": "Promo Type", "field": "promoType" }
        ],
        "rules": [
          { "_id": "r1", "i1": "\"SUMMER20\"", "i2": ">= 100", "o1": "0.20", "o2": "\"percentage\"" },
          { "_id": "r2", "i1": "\"FLAT50\"", "i2": ">= 200", "o1": "50", "o2": "\"fixed\"" },
          { "_id": "r3", "i1": "\"NEWUSER\"", "i2": "", "o1": "0.15", "o2": "\"percentage\"" },
          { "_id": "r4", "i1": "", "i2": "", "o1": "0", "o2": "\"none\"" }
        ],
        "passThrough": true
      }
    },
    {
      "type": "expressionNode",
      "id": "calculate",
      "name": "CalculateFinal",
      "position": { "x": 750, "y": 200 },
      "content": {
        "expressions": [
          { "id": "e1", "key": "baseAmount", "value": "order.subtotal" },
          { "id": "e2", "key": "tierSavings", "value": "$.baseAmount * $nodes.TierDiscount.discount" },
          { "id": "e3", "key": "volumeSavings", "value": "$.baseAmount * $nodes.VolumeDiscount.volumeDiscount" },
          { "id": "e4", "key": "promoSavings", "value": "$nodes.PromoCode.promoType == 'percentage' ? $.baseAmount * $nodes.PromoCode.promoDiscount : $nodes.PromoCode.promoDiscount" },
          { "id": "e5", "key": "totalDiscount", "value": "min([$.tierSavings + $.volumeSavings + $.promoSavings, $.baseAmount * 0.40])" },
          { "id": "e6", "key": "finalPrice", "value": "round($.baseAmount - $.totalDiscount, 2)" }
        ],
        "passThrough": false
      }
    }
  ],
  "edges": [
    { "id": "e1", "sourceId": "input", "targetId": "tierDiscount", "type": "edge" },
    { "id": "e2", "sourceId": "input", "targetId": "volumeDiscount", "type": "edge" },
    { "id": "e3", "sourceId": "input", "targetId": "promoCode", "type": "edge" },
    { "id": "e4", "sourceId": "tierDiscount", "targetId": "calculate", "type": "edge" },
    { "id": "e5", "sourceId": "volumeDiscount", "targetId": "calculate", "type": "edge" },
    { "id": "e6", "sourceId": "promoCode", "targetId": "calculate", "type": "edge" }
  ]
}
