from fastapi import FastAPI, APIRouter, Request
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from security import security_router
import uvicorn

app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
app.include_router(security_router)

templates = Jinja2Templates(directory="templates")


@app.get("/")
async def read_root(request: Request):
    routes = []
    for route in request.app.routes:
        if route.name in ["openapi", "swagger_ui_html", "swagger_ui_redirect", "redoc_html", "static", "read_root"]:
            continue
        routes.append({
            "path": getattr(route, "path", "N/A"),
            "name": getattr(route, "name", "N/A"),
            "methods": list(route.methods) if hasattr(route, "methods") else []
        })
    
    return templates.TemplateResponse(
      request=request,
      name="index.html", 
      context={"routes": routes}
    )

if __name__ == "__main__":
  uvicorn.run(
    "main:app",
    host="0.0.0.0",
    port=8080,
    reload=True
  )
