from datetime import datetime, timezone
from pathlib import Path

from fastapi import FastAPI
from fastapi.responses import FileResponse
from fastapi.staticfiles import StaticFiles


BASE_DIR = Path(__file__).resolve().parent
STATIC_DIR = BASE_DIR / "static"
INDEX_FILE = STATIC_DIR / "index.html"

app = FastAPI(
    title="cPanel FastAPI Test App",
    description="Small FastAPI application with a frontend for cPanel Python app testing.",
    version="1.0.0",
)

app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")


@app.get("/")
async def frontend() -> FileResponse:
    return FileResponse(INDEX_FILE)


@app.get("/api/health")
async def health_check() -> dict[str, str]:
    return {
        "status": "ok",
        "backend": "FastAPI",
        "time_utc": datetime.now(timezone.utc).isoformat(),
    }


@app.get("/api/message")
async def message() -> dict[str, str]:
    return {
        "title": "FastAPI is running",
        "message": "Your cPanel Python application can serve the frontend and backend.",
    }
