#!/bin/bash
set -e

echo "🚀 Setting up ESS Community GitOps devcontainer..."

# Verify all required tools are installed
echo "✅ Verifying installed tools..."
commands=("kubectl" "flux" "helm" "sops" "age" "git" "docker")

for cmd in "${commands[@]}"; do
  if command -v $cmd &> /dev/null; then
    version=$($cmd version 2>/dev/null | head -1 || echo "installed")
    echo "  ✓ $cmd: $version"
  else
    echo "  ✗ $cmd: NOT FOUND"
    exit 1
  fi
done

# Create necessary directories
echo "📁 Creating home directories..."
mkdir -p ~/.kube ~/.ssh ~/.age

# Print useful information
echo ""
echo "📚 Useful commands:"
echo "  - kubectl get pods -n matrix          (check pod status)"
echo "  - flux get helmreleases -A            (check helm releases)"
echo "  - sops apps/production/custom-configs/mas-secret.yaml  (edit secrets)"
echo ""
echo "🔗 For kubeconfig setup:"
echo "  - Copy your ~/.kube/config to access the cluster"
echo "  - Run: kubectl get nodes"
echo ""
echo "✨ Devcontainer setup complete!"
