#!/bin/sh
set -e

echo "🚀 Iniciando WhatsApp Bot - MODO DESARROLLO"
echo "============================================="

# Esperar a que Redis esté disponible
echo "⏳ Esperando Redis..."
until nc -z redis 6379; do
    echo "   Redis no disponible, reintentando..."
    sleep 2
done
echo "✅ Redis disponible"

# Crear directorios necesarios
echo "📁 Creando directorios..."
mkdir -p /var/www/html/logs
mkdir -p /var/www/html/uploads
mkdir -p /run/php
mkdir -p /var/lib/nginx/tmp/client_body
mkdir -p /var/lib/nginx/tmp/proxy
mkdir -p /var/lib/nginx/tmp/fastcgi
mkdir -p /var/lib/nginx/tmp/uwsgi
mkdir -p /var/lib/nginx/tmp/scgi

# Establecer permisos
echo "🔐 Configurando permisos..."
chown -R www-data:www-data /var/www/html/logs
chown -R www-data:www-data /var/www/html/uploads
chmod -R 755 /var/www/html/logs
chmod -R 755 /var/www/html/uploads
chown -R nginx:nginx /var/lib/nginx/tmp
chmod -R 755 /var/lib/nginx/tmp

# Información de desarrollo
echo ""
echo "🛠️  HERRAMIENTAS DE DESARROLLO DISPONIBLES:"
echo "   - Aplicación:         http://localhost:8080"
echo "   - XDebug:             Puerto 9003"
echo "   - Redis Commander:    http://localhost:8082"
echo "   - MailHog:            http://localhost:8025"
echo "   - Adminer:            http://localhost:8083"
echo ""
echo "📝 Configuración:"
echo "   - OPcache:            Desactivado"
echo "   - Error Display:      Activado"
echo "   - Log Level:          DEBUG"
echo "   - Hot Reload:         Activado"
echo ""
echo "============================================="
echo "✅ Entorno de desarrollo listo"
echo ""

# Ejecutar el comando principal
exec "$@"
