{
        "description": "Automatically submit invoices to TaxCore when finalized",
        "priority": 5,
        "max_retries": 3,
        "retry_delay": 300,
        "steps": [
            {
                "step": 1,
                "action": "query",
                "name": "validate_org_config",
                "query": "SELECT org_id, api_base_url, org_tin, certificate_file FROM taxcore_configurations WHERE org_id = ${record.org_id} AND is_active = true",
                "required": true
            },
            {
                "step": 2,
                "action": "query",
                "name": "check_idempotency",
                "query": "SELECT submission_id FROM taxcore_submissions WHERE reference_table = 'invoices' AND reference_id = ${record.invoice_id} AND status = 'success'",
                "required": false
            },
            {
                "step": 3,
                "action": "conditional",
                "name": "skip_if_exists",
                "condition": "step2.result.length > 0",
                "if_true": {"action": "return", "message": "Already submitted"},
                "if_false": {"action": "continue"}
            },
            {
                "step": 4,
                "action": "transform",
                "name": "transform_invoice",
                "source": "${record}",
                "mapping": {
                    "invoiceNumber": "${record.invoice_number}",
                    "invoiceDate": "${record.invoice_date}",
                    "customerName": "${record.customer_name}",
                    "customerTIN": "${record.customer_tin}",
                    "totalAmount": "${record.total_amount}",
                    "taxAmount": "${record.tax_amount}",
                    "lineItems": "${record.line_items}"
                }
            },
            {
                "step": 5,
                "action": "http_post",
                "name": "submit_to_taxcore",
                "url": "http://taxcore-service:3001/submit",
                "headers": {
                    "Content-Type": "application/json"
                },
                "body": "${step4.output}",
                "required": true
            },
            {
                "step": 6,
                "action": "update",
                "name": "update_invoice",
                "query": "UPDATE invoices SET taxcore_invoice_number = ${step5.response.invoiceNumber}, taxcore_submission_id = ${step5.response.submissionId} WHERE invoice_id = ${record.invoice_id}",
                "required": false
            },
            {
                "step": 7,
                "action": "notify",
                "name": "notify_success",
                "channel": "websocket",
                "event": "taxcore:submission:success",
                "data": {
                    "invoice_id": "${record.invoice_id}",
                    "taxcore_invoice_number": "${step5.response.invoiceNumber}"
                }
            }
        ]
    }