#!/usr/bin/env nu
# Triggered by pipeline: deploy-completed
# Subject: ${NATS_NAMESPACE}.deploy.completed
#
# Expected payload: { version: string, commit: string, deployed_by: 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 version     = $payload | get --optional version     | default "unknown"
let commit      = $payload | get --optional commit      | default "unknown"
let deployed_by = $payload | get --optional deployed_by | default "unknown"

print $"[on-deploy-completed] event=($event) version=($version) commit=($commit) by=($deployed_by)"

# Add post-deploy automation here, e.g.:
#   - tag the release in a monitoring system
#   - notify a Slack channel
#   - run a smoke-test suite
