import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

from core.config import settings
from .api import airports, routes, network, stats, predict

app = FastAPI(
    title="RouteRisk API",
    description="Flight delay network analysis and risk assessment",
    version="1.0.0",
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

app.include_router(airports.router)
app.include_router(routes.router)
app.include_router(network.router)
app.include_router(stats.router)
app.include_router(predict.router)

# static files mount has to be last (catch-all)
app.mount("/", StaticFiles(directory=str(settings.frontend_dir), html=True), name="frontend")

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)
