{
  "nodes": [
    {
      "type": "inputNode",
      "id": "input",
      "name": "request",
      "position": { "x": 100, "y": 180 }
    },
    {
      "type": "decisionTableNode",
      "id": "basicEligibility",
      "name": "BasicEligibility",
      "position": { "x": 400, "y": 100 },
      "content": {
        "hitPolicy": "first",
        "inputs": [
          { "id": "i1", "name": "Age", "field": "applicant.age" },
          { "id": "i2", "name": "Income", "field": "applicant.income" },
          { "id": "i3", "name": "Employment Years", "field": "applicant.employmentYears" }
        ],
        "outputs": [
          { "id": "o1", "name": "Eligible", "field": "eligible" },
          { "id": "o2", "name": "Reason", "field": "reason" }
        ],
        "rules": [
          { "_id": "r1", "i1": "< 18", "i2": "", "i3": "", "o1": "false", "o2": "\"Must be 18 or older\"" },
          { "_id": "r2", "i1": ">= 65", "i2": "", "i3": "", "o1": "false", "o2": "\"Age exceeds limit\"" },
          { "_id": "r3", "i1": "", "i2": "< 25000", "i3": "", "o1": "false", "o2": "\"Income below minimum\"" },
          { "_id": "r4", "i1": "", "i2": "", "i3": "< 1", "o1": "false", "o2": "\"Insufficient employment history\"" },
          { "_id": "r5", "i1": "", "i2": "", "i3": "", "o1": "true", "o2": "\"Meets basic requirements\"" }
        ],
        "passThrough": true
      }
    },
    {
      "type": "decisionTableNode",
      "id": "creditCheck",
      "name": "CreditCheck",
      "position": { "x": 400, "y": 260 },
      "content": {
        "hitPolicy": "first",
        "inputs": [
          { "id": "i1", "name": "Credit Score", "field": "applicant.creditScore" }
        ],
        "outputs": [
          { "id": "o1", "name": "Credit Tier", "field": "creditTier" },
          { "id": "o2", "name": "Max Loan Multiple", "field": "multiple" }
        ],
        "rules": [
          { "_id": "r1", "i1": ">= 750", "o1": "\"excellent\"", "o2": "5" },
          { "_id": "r2", "i1": "[700..749]", "o1": "\"good\"", "o2": "4" },
          { "_id": "r3", "i1": "[650..699]", "o1": "\"fair\"", "o2": "3" },
          { "_id": "r4", "i1": "[600..649]", "o1": "\"poor\"", "o2": "2" },
          { "_id": "r5", "i1": "< 600", "o1": "\"denied\"", "o2": "0" }
        ],
        "passThrough": true
      }
    },
    {
      "type": "expressionNode",
      "id": "loanCapacity",
      "name": "LoanCapacity",
      "position": { "x": 750, "y": 180 },
      "content": {
        "expressions": [
          { "id": "e1", "key": "annualIncome", "value": "applicant.income" },
          { "id": "e2", "key": "debtToIncomeLimit", "value": "0.40" },
          { "id": "e3", "key": "maxMonthlyPayment", "value": "$.annualIncome / 12 * $.debtToIncomeLimit" },
          { "id": "e4", "key": "maxLoanByIncome", "value": "$.maxMonthlyPayment * 48" },
          { "id": "e5", "key": "maxLoanByCredit", "value": "$.annualIncome * $nodes.CreditCheck.multiple" },
          { "id": "e6", "key": "approvedAmount", "value": "min([loan.amount, $.maxLoanByIncome, $.maxLoanByCredit])" },
          { "id": "e7", "key": "loanRatio", "value": "loan.amount / $.approvedAmount" }
        ],
        "passThrough": true
      }
    },
    {
      "type": "decisionTableNode",
      "id": "approvalRouter",
      "name": "ApprovalRouter",
      "position": { "x": 1100, "y": 180 },
      "content": {
        "hitPolicy": "first",
        "inputs": [
          { "id": "i1", "name": "Basic Eligible", "field": "eligible" },
          { "id": "i2", "name": "Credit Tier", "field": "creditTier" },
          { "id": "i3", "name": "Loan vs Approved", "field": "loanRatio" }
        ],
        "outputs": [
          { "id": "o1", "name": "Decision", "field": "decision" },
          { "id": "o2", "name": "Next Step", "field": "nextStep" }
        ],
        "rules": [
          { "_id": "r1", "i1": "false", "i2": "", "i3": "", "o1": "\"denied\"", "o2": "\"none\"" },
          { "_id": "r2", "i1": "", "i2": "\"denied\"", "i3": "", "o1": "\"denied\"", "o2": "\"none\"" },
          { "_id": "r3", "i1": "true", "i2": "\"excellent\"", "i3": "<= 1", "o1": "\"approved\"", "o2": "\"auto_fund\"" },
          { "_id": "r4", "i1": "true", "i2": "\"good\"", "i3": "<= 1", "o1": "\"approved\"", "o2": "\"verification\"" },
          { "_id": "r5", "i1": "true", "i2": "\"fair\"", "i3": "<= 1", "o1": "\"review\"", "o2": "\"manual_review\"" },
          { "_id": "r6", "i1": "true", "i2": "", "i3": "> 1", "o1": "\"partial\"", "o2": "\"counter_offer\"" }
        ],
        "passThrough": false
      }
    }
  ],
  "edges": [
    { "id": "e1", "sourceId": "input", "targetId": "basicEligibility", "type": "edge" },
    { "id": "e2", "sourceId": "input", "targetId": "creditCheck", "type": "edge" },
    { "id": "e3", "sourceId": "basicEligibility", "targetId": "loanCapacity", "type": "edge" },
    { "id": "e4", "sourceId": "creditCheck", "targetId": "loanCapacity", "type": "edge" },
    { "id": "e5", "sourceId": "loanCapacity", "targetId": "approvalRouter", "type": "edge" }
  ]
}
