{
        "description": "Update source document when TaxCore submission succeeds",
        "priority": 3,
        "steps": [
            {
                "step": 1,
                "action": "query",
                "name": "get_submission",
                "query": "SELECT * FROM taxcore_submissions WHERE submission_id = ${record.submission_id}",
                "required": true
            },
            {
                "step": 2,
                "action": "conditional",
                "name": "update_by_type",
                "condition": "step1.result[0].reference_table == 'invoices'",
                "if_true": {
                    "action": "update",
                    "query": "UPDATE invoices SET taxcore_invoice_number = ${step1.result[0].taxcore_invoice_number}, taxcore_verified_at = NOW() WHERE invoice_id = ${step1.result[0].reference_id}"
                },
                "if_false": {
                    "action": "update",
                    "query": "UPDATE sales_receipts SET taxcore_receipt_number = ${step1.result[0].taxcore_invoice_number}, taxcore_verified_at = NOW() WHERE receipt_id = ${step1.result[0].reference_id}"
                }
            },
            {
                "step": 3,
                "action": "notify",
                "name": "notify_user",
                "channel": "websocket",
                "event": "document:taxcore:verified",
                "room": "org:${step1.result[0].org_id}",
                "data": {
                    "reference_table": "${step1.result[0].reference_table}",
                    "reference_id": "${step1.result[0].reference_id}",
                    "taxcore_number": "${step1.result[0].taxcore_invoice_number}"
                }
            }
        ]
    }