import os
import sys

# Add backend directory to Python path
CURRENT_DIR = os.path.dirname(__file__)
BACKEND_DIR = os.path.join(CURRENT_DIR, "backend")

if BACKEND_DIR not in sys.path:
    sys.path.insert(0, BACKEND_DIR)
if CURRENT_DIR not in sys.path:
    sys.path.insert(0, CURRENT_DIR)

# Import the FastAPI ASGI app
from backend.app.main import app as fastapi_app

# Namecheap cPanel Passenger uses WSGI.
# We wrap the FastAPI ASGI application with a2wsgi for seamless cPanel compatibility.
try:
    from a2wsgi import ASGIMiddleware
    application = ASGIMiddleware(fastapi_app)
except ImportError:
    # Fallback if a2wsgi is not yet installed
    application = fastapi_app
