# Core Room - Nginx Config Template
# Generated from environment variables
#
# Environment variables:
#   DOMAIN_AMAR        - Amar domain (e.g., amarmascotas.local.com or amar.room.mcrn.ar)
#   DOMAIN_SOLEPRINT    - Soleprint domain (e.g., soleprint.local.com or soleprint.mcrn.ar)
#   USE_SSL            - true/false - whether to use SSL
#   SSL_CERT_PATH      - Path to SSL certificate (if USE_SSL=true)
#   SSL_KEY_PATH       - Path to SSL key (if USE_SSL=true)
#   BACKEND_PORT       - Backend port (default: 8000)
#   FRONTEND_PORT      - Frontend port (default: 3000)
#   SOLEPRINT_PORT      - Soleprint port (default: 13000)

# =============================================================================
# AMAR - Frontend + Backend
# =============================================================================
server {
    listen 80;
    server_name ${DOMAIN_AMAR};
${SSL_REDIRECT}
    # Backend API
    location /api/ {
        proxy_pass http://127.0.0.1:${BACKEND_PORT}/api/;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_read_timeout 300;
    }

    # Django admin
    location /admin/ {
        proxy_pass http://127.0.0.1:${BACKEND_PORT}/admin/;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
    }

    # Django static files
    location /static/ {
        proxy_pass http://127.0.0.1:${BACKEND_PORT}/static/;
    }

    # Frontend (default)
    location / {
        proxy_pass http://127.0.0.1:${FRONTEND_PORT};
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_read_timeout 300;

        # WebSocket support for Next.js hot reload
        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

${SSL_SERVER_BLOCK}

# =============================================================================
# SOLEPRINT - Main Service + Ecosystem
# =============================================================================
server {
    listen 80;
    server_name ${DOMAIN_SOLEPRINT};
${SOLEPRINT_SSL_REDIRECT}
    # Artery - API Gateway
    location /artery/ {
        proxy_pass http://127.0.0.1:${ARTERY_PORT}/;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
    }

    # Album - Media Service
    location /album/ {
        proxy_pass http://127.0.0.1:${ALBUM_PORT}/;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
    }

    # Ward - Admin Interface
    location /ward/ {
        proxy_pass http://127.0.0.1:${WARD_PORT}/;
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
    }

    # Soleprint - Main Service (default)
    location / {
        proxy_pass http://127.0.0.1:${SOLEPRINT_PORT};
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
    }
}

${SOLEPRINT_SSL_SERVER_BLOCK}
