import os
import sys

sys.path.insert(0, os.path.dirname(__file__))

# Si Passenger ne supporte pas ASGI nativement, il faut utiliser l'adaptateur a2wsgi pour transformer l'application FastAPI en WSGI.
# C'est confirmé : ce Passenger (cPanel/EA-ruby27) n'a pas la détection ASGI native — 
# il charge tout via wsgi-loader.py et appelle ton app en mode WSGI pur (app(env, start_response)), alors que FastAPI/Starlette attend la signature ASGI (scope, receive, send). D'où le TypeError.
# Solution : adapter ASGI → WSGI
# Il faut un adaptateur qui transforme les appels WSGI de Passenger en appels ASGI compatibles FastAPI. Le plus simple est le paquet a2wsgi.

from a2wsgi import ASGIMiddleware
from app.main import app as fastapi_app
application = ASGIMiddleware(fastapi_app) # type: ignore[arg-type]

# Si support ASGI natif, il suffit de décommenter la ligne suivante pour utiliser directement l'application FastAPI.
# from app.main import app as application  # 'main' = nom de ton fichier FastAPI (main.py -> app = FastAPI())


__all__ = ['application']