[
        {
            "step": 1,
            "name": "get_source_record",
            "action": "query",
            "description": "Retrieve original invoice/receipt details",
            "query": "SELECT * FROM ${record.reference_table} WHERE ${record.reference_table}.${record.reference_table}_id = ${record.reference_id} LIMIT 1",
            "output": "source_record",
            "on_error": "continue"
        },
        {
            "step": 2,
            "name": "get_org_details",
            "action": "query",
            "description": "Get organization name",
            "query": "SELECT name FROM orgs WHERE org_id = ${record.org_id} LIMIT 1",
            "output": "org",
            "on_error": "continue"
        },
        {
            "step": 3,
            "name": "send_email_notification",
            "action": "email",
            "description": "Email admin about failed submission",
            "to": "admin@example.com",
            "subject": "TaxCore Submission Failed: ${source_record.invoice_number}",
            "template": "taxcore_failure",
            "data": {
                "submission_id": "${record.submission_id}",
                "org_name": "${org.name}",
                "reference_type": "${record.reference_table}",
                "reference_number": "${source_record.invoice_number}",
                "error_message": "${record.error_message}",
                "attempts": "${record.attempts}",
                "last_attempt": "${record.last_attempt_at}"
            },
            "on_error": "log"
        },
        {
            "step": 4,
            "name": "create_system_notification",
            "action": "insert",
            "description": "Create in-app notification",
            "table": "notifications",
            "data": {
                "notification_id": "${uuid}",
                "user_id": null,
                "org_id": "${record.org_id}",
                "type": "error",
                "title": "TaxCore Submission Failed",
                "message": "Failed to submit ${record.reference_table} after ${record.attempts} attempts. Error: ${record.error_message}",
                "link": "/taxcore/submissions/${record.submission_id}",
                "is_read": false,
                "created_at": "${now}"
            },
            "on_error": "log"
        },
        {
            "step": 5,
            "name": "websocket_alert",
            "action": "notify",
            "description": "Send real-time websocket alert",
            "channel": "websocket",
            "event": "taxcore:submission:failed",
            "data": {
                "submission_id": "${record.submission_id}",
                "org_id": "${record.org_id}",
                "reference_table": "${record.reference_table}",
                "error_message": "${record.error_message}"
            }
        }
    ]