{
  "name": "Checkout policy",
  "description": "Discounts, shipping, age checks and loyalty points for the web shop.",
  "rules": [
    {
      "id": "member-discount",
      "description": "Adult VIPs and customers of five years or more get 10% off.",
      "priority": 40,
      "condition": {
        "type": "group",
        "operator": "AND",
        "rules": [
          { "field": "Customer.Age", "operator": "GreaterThanOrEqual", "value": 18 },
          {
            "type": "group",
            "operator": "OR",
            "rules": [
              { "field": "Customer.IsVip", "operator": "Equals", "value": true },
              { "field": "Customer.LoyaltyYears", "operator": "GreaterThanOrEqual", "value": 5 }
            ]
          }
        ]
      },
      "actions": [
        { "type": "addToOutput", "target": "DiscountPercent", "value": 10 },
        { "type": "appendToOutput", "target": "Notes", "value": "member discount" }
      ]
    },
    {
      "id": "big-basket",
      "description": "Another 5% on baskets of 200 or more, on top of any member discount.",
      "priority": 30,
      "condition": { "field": "Order.Total", "operator": "GreaterThanOrEqual", "value": 200 },
      "actions": [
        { "type": "addToOutput", "target": "DiscountPercent", "value": 5 },
        { "type": "appendToOutput", "target": "Notes", "value": "big basket" }
      ]
    },
    {
      "id": "age-check",
      "description": "Alcohol and tobacco need ID on delivery.",
      "priority": 20,
      "condition": {
        "field": "Order.Lines",
        "operator": "Any",
        "condition": { "field": "Category", "operator": "In", "value": ["alcohol", "tobacco"] }
      },
      "actions": [
        { "type": "setOutput", "target": "IdRequired", "value": true },
        { "type": "appendToOutput", "target": "Notes", "value": "ID required on delivery" }
      ]
    },
    {
      "id": "shipping",
      "description": "Free shipping from 50; otherwise a flat fee.",
      "priority": 10,
      "condition": { "field": "Order.Total", "operator": "GreaterThanOrEqual", "value": 50 },
      "actions": [ { "type": "setOutput", "target": "Shipping", "value": 0 } ],
      "else": [ { "type": "setOutput", "target": "Shipping", "value": 5.95 } ]
    },
    {
      "id": "loyalty-points",
      "description": "One point per ten dollars, for everyone.",
      "condition": { "field": "Order.Total", "operator": "GreaterThan", "value": 0 },
      "actions": [
        {
          "type": "setOutput",
          "target": "Points",
          "value": {
            "op": "divide",
            "operands": [ { "field": "Order.Total" }, 10 ]
          }
        },
        {
          "type": "setOutput",
          "target": "Greeting",
          "value": {
            "op": "concat",
            "operands": [
              "Thanks for your order, ",
              { "field": "Customer.Name" },
              "!"
            ]
          }
        }
      ]
    }
  ]
}
