#!/usr/bin/env nu
# Triggered by pipeline: content-published
# Subject: ${NATS_NAMESPACE}.content.published
#
# Expected payload: { content_type: string, language: string, id: string }
#
# Env vars set by the executor:
#   PIPELINE_EVENT   — actual NATS subject
#   PIPELINE_PAYLOAD — raw JSON body

let event   = $env.PIPELINE_EVENT
let payload = $env.PIPELINE_PAYLOAD | from json

let content_type = $payload | get --optional content_type | default "unknown"
let language     = $payload | get --optional language     | default "unknown"
let id           = $payload | get --optional id           | default "unknown"

print $"[on-content-published] event=($event) type=($content_type) lang=($language) id=($id)"

# Add post-publish automation here, e.g.:
#   - invalidate a CDN edge cache
#   - trigger a search index update
#   - send a webhook to an external service
