#!/bin/bash
# MC Cars Deployment Configuration Setup
# Usage: ./deploy-setup.sh https://www.mc-cars.at

set -e

if [ $# -eq 0 ]; then
    echo "Usage: ./deploy-setup.sh <domain>"
    echo "Example: ./deploy-setup.sh https://www.mc-cars.at"
    exit 1
fi

DOMAIN="$1"

echo "🚀 Configuring MC Cars for: $DOMAIN"

# Update environment variables
sed -i "s|SITE_URL=.*|SITE_URL=$DOMAIN|" .env
sed -i "s|SUPABASE_PUBLIC_URL=.*|SUPABASE_PUBLIC_URL=$DOMAIN|" .env
sed -i "s|N8N_WEBHOOK_URL=.*|N8N_WEBHOOK_URL=$DOMAIN/webhook/manual-email-send|" .env

echo "✅ Updated .env:"
echo "   SITE_URL=$DOMAIN"
echo "   SUPABASE_PUBLIC_URL=$DOMAIN"
echo "   N8N_WEBHOOK_URL=$DOMAIN/webhook/manual-email-send"

echo ""
echo "📋 Next steps:"
echo "   1. Verify .env looks correct: grep -E 'SITE_URL|SUPABASE_PUBLIC_URL|N8N_WEBHOOK_URL' .env"
echo "   2. Restart services: docker-compose down && docker-compose up -d --build"
echo "   3. Test webhook: curl '$DOMAIN/webhook/manual-email-send' -d 'sales_order_id=test'"
