{
  "$schema": "/schema/v1.json",
  "type": "flow",
  "title": "How an order gets processed",
  "nodes": [
    {
      "id": "start",
      "label": "Order received",
      "kind": "start",
      "icon": "cart"
    },
    {
      "id": "stock",
      "label": "In stock?",
      "kind": "decision"
    },
    {
      "id": "notify",
      "label": "Notify customer",
      "description": "restock date",
      "icon": "mail"
    },
    {
      "id": "pay",
      "label": "Charge",
      "description": "card or bank transfer",
      "icon": "card"
    },
    {
      "id": "ship",
      "label": "Prepare shipment",
      "icon": "package"
    },
    {
      "id": "done",
      "label": "Delivered",
      "kind": "end",
      "icon": "check"
    }
  ],
  "edges": [
    {
      "id": "e1",
      "from": "start",
      "to": "stock",
      "carries": "order"
    },
    {
      "id": "no",
      "from": "stock",
      "to": "notify",
      "label": "no"
    },
    {
      "id": "yes",
      "from": "stock",
      "to": "pay",
      "label": "yes"
    },
    {
      "id": "e4",
      "from": "pay",
      "to": "ship",
      "carries": "$"
    },
    {
      "id": "e5",
      "from": "ship",
      "to": "done"
    }
  ],
  "steps": [
    {
      "show": [
        "start"
      ],
      "caption": "An order comes in",
      "notes": "Start with the customer: an order just came in from the store."
    },
    {
      "show": [
        "e1"
      ],
      "flow": "e1",
      "state": {
        "stock": "pending"
      },
      "caption": "The inventory is checked",
      "notes": "Before charging anything we check the warehouse. This takes a moment, hence the spinner."
    },
    {
      "show": [
        "no"
      ],
      "flow": "no",
      "state": {
        "stock": "warning",
        "no": "error",
        "notify": "error"
      },
      "caption": "Out of stock: the customer is told",
      "notes": "Worst case first: no stock. We don't charge, we tell the customer when it comes back."
    },
    {
      "show": [
        "yes"
      ],
      "flow": "yes",
      "state": {
        "stock": "success",
        "no": "default",
        "notify": "default",
        "pay": "pending"
      },
      "caption": "In stock: the payment is attempted",
      "notes": "Happy path: with stock, we try to charge the card or transfer."
    },
    {
      "show": [
        "e4"
      ],
      "flow": "e4",
      "state": {
        "pay": "success",
        "ship": "pending"
      },
      "caption": "Payment approved, shipping starts",
      "notes": "Payment approved, so the warehouse starts preparing the box."
    },
    {
      "show": [
        "e5"
      ],
      "flow": "e5",
      "state": {
        "ship": "success",
        "done": "success"
      },
      "caption": "Delivered",
      "notes": "And it's delivered. Ask: where could this process fail besides stock?"
    }
  ]
}
