# scripts/web/run_web_api.py
import os
import sys
from pathlib import Path
import uvicorn

# Añade el root del proyecto al PYTHONPATH
sys.path.insert(0, str(Path(__file__).parent.parent.parent))

from scripts.common.env import setup_environment


def main():
    # 🔑 Cargar entorno UNA sola vez
    setup_environment()

    host = os.getenv("WEB_HOST", "127.0.0.1")
    port = int(os.getenv("WEB_PORT", 8000))
    reload = os.getenv("WEB_RELOAD", "false").lower() == "true"

    uvicorn.run(
        "src.web.api.v2.main:app",
        host=host,
        port=port,
        reload=reload,
        log_level="info",
    )


if __name__ == "__main__":
    main()
