{
  "decision": {
    "name": "Example \u00b7 Invoice payment",
    "inputs": {
      "invoice_amount": {
        "type": "number >= 0",
        "desc": "Invoice amount in USD",
        "from": "invoice JSON"
      },
      "invoice_date": {
        "type": "date",
        "desc": "Invoice date",
        "from": "invoice JSON"
      },
      "payment_on": {
        "type": "date",
        "desc": "Payment date",
        "from": "invoice JSON"
      },
      "approved": {
        "type": "boolean",
        "desc": "Has this invoice been approved?",
        "from": "invoice JSON"
      }
    },
    "decisions": {
      "elapsed_days": {
        "type": "number",
        "desc": "Calendar days from invoice to payment",
        "expr": "(payment_on - invoice_date).days"
      },
      "discount_window_days": {
        "type": "number",
        "desc": "Inclusive early-payment window",
        "expr": "10"
      },
      "discount_rate": {
        "type": "number",
        "desc": "Early-payment discount fraction",
        "expr": "0.02"
      },
      "payment_action": {
        "type": "discount|full|review",
        "desc": "How should this invoice be paid?",
        "table": [
          [
            "approved",
            "elapsed_days",
            "elapsed_days <= discount_window_days",
            "=> discount|full|review",
            "# why"
          ],
          [
            "false",
            "-",
            "-",
            "review",
            "Invoice needs approval before payment."
          ],
          [
            "-",
            "< 0",
            "-",
            "review",
            "Payment predates the invoice; check the dates."
          ],
          [
            "true",
            "-",
            "true",
            "discount",
            "Approved invoice is within the inclusive 10-day discount window."
          ],
          [
            "-",
            "-",
            "-",
            "full",
            "Approved invoice is outside the early-payment window."
          ]
        ]
      },
      "discount_amount": {
        "type": "number",
        "desc": "Discount amount in USD",
        "expr": "if payment_action = \"discount\" then invoice_amount * discount_rate else 0"
      },
      "payment_amount": {
        "type": "number",
        "desc": "Amount to pay in USD; zero while review is required",
        "expr": "if payment_action = \"review\" then 0 else invoice_amount - discount_amount"
      }
    }
  },
  "state": {
    "invoice_amount": 25000,
    "invoice_date": "2026-10-01",
    "payment_on": "2026-10-11",
    "approved": true
  }
}
