{
        "description": "Submit invoice to tax authority via TaxCore",
        "trigger": {
            "event": "invoice:status:pending",
            "table": "invoices",
            "condition": "status == \"pending\" && taxcore_submission_id == null"
        },
        "steps": [
            {
                "order": 1,
                "type": "validation",
                "rules": [
                    {"field": "invoice_number", "required": true},
                    {"field": "amount", "min": 0},
                    {"field": "line_items", "minLength": 1}
                ],
                "description": "Validate invoice data before submission"
            },
            {
                "order": 2,
                "type": "action",
                "action": "invoices:submit-taxcore",
                "description": "Submit invoice to TaxCore API",
                "retry": {
                    "maxAttempts": 3,
                    "backoff": "exponential",
                    "initialDelay": 5000
                }
            },
            {
                "order": 3,
                "type": "update",
                "table": "invoices",
                "fields": {
                    "status": "submitted",
                    "taxcore_submission_id": "{taxcore_response.submission_id}",
                    "taxcore_submitted_at": "NOW()",
                    "taxcore_verification_url": "{taxcore_response.verification_url}",
                    "taxcore_qr_code": "{taxcore_response.qr_code}",
                    "taxcore_receipt_data": "{taxcore_response}"
                },
                "description": "Update invoice with TaxCore response"
            },
            {
                "order": 4,
                "type": "notification",
                "recipients": ["created_by", "accounting_team"],
                "template": "invoice_submitted_taxcore",
                "data": {
                    "invoice_number": "{invoice_number}",
                    "submission_id": "{taxcore_submission_id}",
                    "verification_url": "{taxcore_verification_url}"
                },
                "channels": ["email", "push"]
            },
            {
                "order": 5,
                "type": "emit",
                "event": "invoice:taxcore:submitted",
                "data": {
                    "invoice_id": "{invoice_id}",
                    "submission_id": "{taxcore_submission_id}"
                }
            }
        ],
        "onError": {
            "action": "rollback",
            "update": {
                "table": "invoices",
                "fields": {
                    "status": "draft"
                }
            },
            "notification": {
                "recipients": ["created_by", "accounting_team"],
                "template": "taxcore_submission_failed",
                "data": {
                    "invoice_number": "{invoice_number}",
                    "error": "{error_message}"
                }
            }
        }
    }