{
  "name": "Bella Plugin \u2014 BPPE Citation Lookup",
  "nodes": [
    {
      "id": "8f057efb-9a9a-4b5b-bdf7-95e65965b704",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "1828d6e4-6079-4f48-8a98-96f53cfa154a",
      "name": "Note: BPPE Scrape",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        280,
        -120
      ],
      "parameters": {
        "content": "Basic HTML scrape. If BPPE requires JS rendering, replace this node with an Apify node.",
        "height": 80,
        "width": 360,
        "color": 4
      }
    },
    {
      "id": "a067e3c3-8b0b-43d3-aa9d-9470ba8b731c",
      "name": "HTTP Request: BPPE Search",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        280,
        0
      ],
      "parameters": {
        "method": "GET",
        "url": "https://www.bppe.ca.gov/enforcement/citation.shtml",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "school",
              "value": "={{ $json.school_name }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      }
    },
    {
      "id": "15d133ed-45fc-4f98-aa68-b835ef4d5456",
      "name": "Code: Parse BPPE Response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        0
      ],
      "parameters": {
        "jsCode": "const html = $input.first().json.data || '';\nconst schoolName = $('Execute Workflow Trigger').first().json.school_name || '';\n\n// Extract citation number\nconst citationMatch = html.match(/Citation\\s*#?\\s*([\\w-]+)/i);\nconst dateMatch = html.match(/(\\d{1,2}\\/\\d{1,2}\\/\\d{2,4})/i);\nconst fineMatch = html.match(/\\$([\\d,]+)/i);\nconst violationMatch = html.match(/Violation[:\\s]+([^<\\n]+)/i);\nconst statusMatch = html.match(/Status[:\\s]+([^<\\n]+)/i);\n\nconst found = !!citationMatch;\nreturn [{ json: {\n  found,\n  school_name: schoolName,\n  citation_number: citationMatch ? citationMatch[1].trim() : null,\n  citation_date: dateMatch ? dateMatch[1] : null,\n  fine_amount: fineMatch ? fineMatch[1] : null,\n  violation_type: violationMatch ? violationMatch[1].trim() : null,\n  resolution_status: statusMatch ? statusMatch[1].trim() : null,\n} }];"
      }
    },
    {
      "id": "691dc777-1bca-483a-86a8-8cd1a1ca96e0",
      "name": "If: Found Data",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        840,
        0
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": false,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ $json.found }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "true"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "fc5c1976-4937-419c-918a-6d57356eb9d6",
      "name": "Set: Output Citation",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        1120,
        -100
      ],
      "parameters": {
        "mode": "passthrough"
      }
    },
    {
      "id": "783463bf-b3d3-4865-9960-f7b1669aa139",
      "name": "Set: Not Found",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [
        1120,
        100
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "e70f0731-bd8b-4d13-b8b6-6c22c712e405",
              "name": "found",
              "value": false,
              "type": "boolean"
            },
            {
              "id": "9915614a-46b0-4b04-9d9f-9017ef5b6e0d",
              "name": "school_name",
              "value": "={{ $json.school_name }}",
              "type": "string"
            },
            {
              "id": "f6598ea8-3f54-48ca-a0da-7c2671bca05a",
              "name": "message",
              "value": "No BPPE citation found for this school",
              "type": "string"
            }
          ]
        }
      }
    }
  ],
  "connections": {
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "HTTP Request: BPPE Search",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request: BPPE Search": {
      "main": [
        [
          {
            "node": "Code: Parse BPPE Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code: Parse BPPE Response": {
      "main": [
        [
          {
            "node": "If: Found Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If: Found Data": {
      "main": [
        [
          {
            "node": "Set: Output Citation",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Set: Not Found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}