#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
COMPOSE_DIR="$ROOT_DIR/compose"
HELM_DIR="$ROOT_DIR/helm/stellaops"

compose_profiles=(
  "docker-compose.dev.yaml:env/dev.env.example"
  "docker-compose.stage.yaml:env/stage.env.example"
  "docker-compose.airgap.yaml:env/airgap.env.example"
)

if command -v docker >/dev/null 2>&1; then
  for entry in "${compose_profiles[@]}"; do
    IFS=":" read -r compose_file env_file <<<"$entry"
    printf '→ validating %s with %s\n' "$compose_file" "$env_file"
    docker compose \
      --env-file "$COMPOSE_DIR/$env_file" \
      -f "$COMPOSE_DIR/$compose_file" config >/dev/null
  done
else
  echo "⚠️  docker CLI not found; skipping compose validation" >&2
fi

helm_values=(
  "$HELM_DIR/values-dev.yaml"
  "$HELM_DIR/values-stage.yaml"
  "$HELM_DIR/values-airgap.yaml"
)

if command -v helm >/dev/null 2>&1; then
  for values in "${helm_values[@]}"; do
    printf '→ linting Helm chart with %s\n' "$(basename "$values")"
    helm lint "$HELM_DIR" -f "$values"
    helm template test-release "$HELM_DIR" -f "$values" >/dev/null
  done
else
  echo "⚠️  helm CLI not found; skipping Helm lint/template" >&2
fi

printf 'Profiles validated (where tooling was available).\n'
