#!/bin/bash
set -e

echo "🏢 CitySensor Docker Registry Setup"
echo "====================================="
echo ""

# Check if required files exist
if [ ! -f .env.build.example ]; then
    echo "❌ Error: .env.build.example not found!"
    exit 1
fi

echo "📋 Setup Steps:"
echo ""

echo "1️⃣  Create build configuration:"
echo "   cp .env.build.example .env.registry"
echo "   # Edit .env.registry with your CitySensor credentials"
echo ""

echo "2️⃣  Required values in .env.registry:"
echo "   DOCKER_REGISTRY=docker.citysensor.de"
echo "   DOCKER_USERNAME=your_citysensor_username"
echo "   DOCKER_PASSWORD=your_citysensor_password"
echo "   DOMAIN=your.domain.com"
echo "   API_BASE_URL=https://rezepte.your.domain.com/api"
echo ""

echo "3️⃣  Build and push to CitySensor registry:"
echo "   ./build-and-push.sh"
echo ""

echo "4️⃣  For server deployment, create .env.production:"
echo "   cp .env.traefik.example .env.production"
echo "   # Edit with your server configuration"
echo ""

echo "5️⃣  Server deployment files needed:"
echo "   - docker-compose.traefik.yml"
echo "   - .env.production"
echo "   - *.sql files"
echo "   - deploy-traefik.sh"
echo ""

echo "6️⃣  Deploy on server:"
echo "   ./deploy-traefik.sh"
echo ""

echo "🔧 Example .env.registry content:"
echo "DOMAIN=example.com"
echo "ACME_EMAIL=admin@example.com"
echo "API_BASE_URL=https://rezepte.example.com/api"
echo "MYSQL_PASSWORD=secure_db_password"
echo "MYSQL_ROOT_PASSWORD=super_secure_root_password"
echo "DOCKER_REGISTRY=docker.citysensor.de"
echo "DOCKER_USERNAME=your_username"
echo "DOCKER_PASSWORD=your_password"
echo "BACKEND_IMAGE=docker.citysensor.de/rezepte-klaus-backend:latest"
echo "FRONTEND_IMAGE=docker.citysensor.de/rezepte-klaus-frontend:latest"
echo ""

echo "✅ After setup, your app will be available at:"
echo "   https://rezepte.your.domain.com"
echo ""

echo "🛡️  Security Note:"
echo "   Never commit .env.registry or .env.production to version control!"