#!/bin/bash
# Quick test without Docker containers - just check files

echo "🧪 Quick Git Deployment Test"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# Test 1: Entrypoint Script
echo "1️⃣  Checking entrypoint.sh..."
if grep -q "GIT_REPOSITORY_URL" docker/entrypoint.sh; then
    echo "   ✅ GIT_REPOSITORY_URL found"
else
    echo "   ❌ GIT_REPOSITORY_URL NOT found"
fi

if grep -q "git clone" docker/entrypoint.sh; then
    echo "   ✅ git clone found"
else
    echo "   ❌ git clone NOT found"
fi

if grep -q "composer install" docker/entrypoint.sh; then
    echo "   ✅ composer install found"
else
    echo "   ❌ composer install NOT found"
fi

echo ""

# Test 2: Dockerfile
echo "2️⃣  Checking Dockerfile.production..."
if grep -q "git" Dockerfile.production; then
    echo "   ✅ git in Dockerfile"
else
    echo "   ❌ git NOT in Dockerfile"
fi

if grep -q "composer" Dockerfile.production; then
    echo "   ✅ composer in Dockerfile"
else
    echo "   ❌ composer NOT in Dockerfile"
fi

if grep -q "entrypoint.sh" Dockerfile.production; then
    echo "   ✅ entrypoint.sh in Dockerfile"
else
    echo "   ❌ entrypoint.sh NOT in Dockerfile"
fi

echo ""

# Test 3: Docker Compose
echo "3️⃣  Checking docker-compose.yml..."
if grep -q "GIT_REPOSITORY_URL" deployment/stacks/application/docker-compose.yml; then
    echo "   ✅ GIT_REPOSITORY_URL in docker-compose.yml"
else
    echo "   ❌ GIT_REPOSITORY_URL NOT in docker-compose.yml"
fi

echo ""

# Test 4: Ansible Template
echo "4️⃣  Checking Ansible template..."
if grep -q "GIT_REPOSITORY_URL" deployment/ansible/templates/application.env.j2; then
    echo "   ✅ GIT_REPOSITORY_URL in Ansible template"
else
    echo "   ❌ GIT_REPOSITORY_URL NOT in Ansible template"
fi

echo ""

# Test 5: Show entrypoint Git section
echo "5️⃣  Entrypoint Git section (first 10 lines):"
echo "   ────────────────────────────────────────────────────"
grep -A 10 "Git Clone/Pull functionality" docker/entrypoint.sh | head -12 | sed 's/^/   /'

echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Quick test complete!"
echo ""
echo "📝 Next steps:"
echo "   1. Image bauen: docker build -f Dockerfile.production -t registry.michaelschiemer.de/framework:latest ."
echo "   2. Git-Variablen in .env setzen (auf Production Server)"
echo "   3. Container neu starten: docker compose restart app"
echo "   4. Logs prüfen: docker logs app | grep -E '(Git|Clone|Pull)'"
