#!/bin/bash
# Complete Azure setup using .env file
# This script orchestrates the entire Azure deployment setup process

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"

echo "╔══════════════════════════════════════════════════════════════╗"
echo "║   COMPLETE AZURE SETUP FROM .ENV FILE                       ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""

# Step 1: Integrate existing CDN config if available
echo "Step 1: Integrating existing CDN configuration..."
"$SCRIPT_DIR/azure-integrate-cdn-env.sh"

# Step 2: Validate environment
echo ""
echo "Step 2: Validating environment variables..."
source "$SCRIPT_DIR/azure-validate-env.sh"

# Step 3: Sync to Terraform
echo ""
echo "Step 3: Syncing environment to Terraform..."
"$SCRIPT_DIR/azure-sync-env-to-terraform.sh"

# Step 4: Update Kubernetes configs
echo ""
echo "Step 4: Updating Kubernetes configurations..."
"$SCRIPT_DIR/azure-update-k8s-secrets.sh"

echo ""
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║   SETUP COMPLETE - READY FOR DEPLOYMENT                     ║"
echo "╚══════════════════════════════════════════════════════════════╝"
echo ""
echo "✅ All configurations synced from .env file"
echo ""
echo "Next steps:"
echo "  1. Review Terraform plan:"
echo "     cd infra/terraform && terraform plan"
echo ""
echo "  2. Deploy infrastructure:"
echo "     ./infra/scripts/azure-deploy.sh"
echo ""
echo "  3. After deployment, update Kubernetes secrets:"
echo "     ./infra/scripts/azure-update-k8s-secrets.sh"
echo ""
echo "  4. Deploy services to Kubernetes:"
echo "     kubectl apply -k infra/k8s/overlays/dev"

