{
        "description": "Notify administrators when TaxCore submission fails after max attempts",
        "priority": 8,
        "condition": "status = 'failed' AND attempts >= 3",
        "steps": [
            {
                "step": 1,
                "action": "query",
                "name": "get_source_document",
                "query": "SELECT * FROM ${record.reference_table} WHERE ${record.reference_table}_id = ${record.reference_id}"
            },
            {
                "step": 2,
                "action": "query",
                "name": "get_org_info",
                "query": "SELECT * FROM orgs WHERE org_id = ${record.org_id}"
            },
            {
                "step": 3,
                "action": "email",
                "name": "send_alert_email",
                "to": "${step2.admin_email}",
                "subject": "TaxCore Submission Failed: ${record.reference_table} ${record.reference_id}",
                "template": "taxcore_failure_alert",
                "data": {
                    "submission": "${record}",
                    "document": "${step1}",
                    "org": "${step2}"
                }
            },
            {
                "step": 4,
                "action": "insert",
                "name": "create_notification",
                "table": "notifications",
                "data": {
                    "org_id": "${record.org_id}",
                    "type": "taxcore_submission_failed",
                    "severity": "error",
                    "title": "TaxCore Submission Failed",
                    "message": "Submission ${record.submission_id} failed after ${record.attempts} attempts",
                    "link": "/taxcore/submissions/${record.submission_id}"
                }
            },
            {
                "step": 5,
                "action": "notify",
                "name": "websocket_alert",
                "channel": "websocket",
                "event": "taxcore:alert:failure",
                "data": "${record}"
            }
        ]
    }