use super::super::native_helpers::{NativeEventContext, enqueue_outbox_event_with_context};
use super::TenantServiceImpl;
pub(crate) async fn emit_event(
svc: &TenantServiceImpl,
topic: &str,
operation: &str,
partition_key: &str,
tenant_id: &str,
payload: serde_json::Value,
) {
let Some(pool) = svc.pg_pool.as_ref() else {
return;
};
enqueue_outbox_event_with_context(
pool,
svc.outbox_relation.as_deref(),
topic,
partition_key,
tenant_id,
"",
payload,
NativeEventContext {
operation: operation.to_string(),
target_resource: tenant_id.to_string(),
..NativeEventContext::default()
},
Some(&svc.metrics),
)
.await;
}
pub(crate) fn tenant_lifecycle_event_payload(
tenant_id: &str,
code: &str,
status: &str,
) -> serde_json::Value {
serde_json::json!({
"tenant_id": tenant_id,
"code": code,
"status": status,
})
}
pub(crate) fn tenant_config_event_payload(tenant_id: &str, config_key: &str) -> serde_json::Value {
serde_json::json!({
"tenant_id": tenant_id,
"config_key": config_key,
})
}