#!/usr/bin/env bash
# GENERATED by tools/pack_assets.py: Government and Public Sector pack 2.0.0 — first dataset through the API.
# Needs DATANIVRA_API_URL (control-plane origin, no /v1) and DATANIVRA_API_TOKEN (your session
# token; never commit it). Replace the placeholder ids (00000000-…) in the JSON bodies with yours.
# Every route is a common pack route: the pack id is a path parameter.
set -euo pipefail
for required in DATANIVRA_API_URL DATANIVRA_API_TOKEN; do
  [ -n "${!required:-}" ] || { echo "set ${required}" >&2; exit 2; }
done
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
api() {
  curl -fsS -H "Authorization: Bearer ${DATANIVRA_API_TOKEN}" -H "Content-Type: application/json" "$@"
}

# 0. Optional: start the hosted synthetic sandbox with this pack's estate (no install needed).
api -X POST "${DATANIVRA_API_URL}/v1/sandbox" --data @"${HERE}/sandbox.json"

# 1. Inspect the pack: versions, entitlement, activation checks, agent compatibility, templates.
api "${DATANIVRA_API_URL}/v1/industry-packs/government"

# 2. Activate it for your organisation (entitlement, integrity and dependency checks apply).
api -X POST "${DATANIVRA_API_URL}/v1/industry-packs/government/enable"

# 3. Draft the pack's policies (MASKING, CLASSIFICATION, CERTIFICATION, SUBSET, REFRESH) as DRAFTs.
api -X POST "${DATANIVRA_API_URL}/v1/industry-packs/government/policy-drafts" \
  --data @"${HERE}/policy-drafts.json"

# 4. Submit each draft; a second person approves it with the checksum they reviewed.
POLICY_ID="${POLICY_ID:-00000000-0000-4000-8000-000000000003}"
api -X POST "${DATANIVRA_API_URL}/v1/policies/${POLICY_ID}/versions/1/submit"
api -X POST "${DATANIVRA_API_URL}/v1/policies/${POLICY_ID}/versions/1/approve" \
  --data @"${HERE}/policy-approval.json"

# 5. Request the dataset (pack scenarios included); the agent builds and certifies it customer-side.
api -X POST "${DATANIVRA_API_URL}/v1/dataset-requests" -H "Idempotency-Key: government-first-dataset" \
  --data @"${HERE}/dataset-request.json"

# 6. Follow the job, then read the certification report and the evidence references.
DATASET_ID="${DATASET_ID:-00000000-0000-4000-8000-000000000006}"
api "${DATANIVRA_API_URL}/v1/jobs?dataset_id=${DATASET_ID}"
api "${DATANIVRA_API_URL}/v1/certification-reports?dataset_id=${DATASET_ID}"
api "${DATANIVRA_API_URL}/v1/evidence?dataset_id=${DATASET_ID}"

# 7. Provision the certified version into another non-production environment.
api -X POST "${DATANIVRA_API_URL}/v1/datasets/${DATASET_ID}/versions/1/provision" \
  -H "Idempotency-Key: government-provision-1" --data @"${HERE}/provision.json"
