"""HTML shell — serves the single-page dashboard."""
from __future__ import annotations

from fastapi import HTTPException, Request
from fastapi.responses import HTMLResponse

from ._common import DASHBOARD_HTML, router


@router.get("/", response_class=HTMLResponse, include_in_schema=False)
def dashboard() -> HTMLResponse:
    """Serve the single-page dashboard."""
    if not DASHBOARD_HTML.exists():
        raise HTTPException(500, f"dashboard template missing: {DASHBOARD_HTML}")
    return HTMLResponse(DASHBOARD_HTML.read_text(encoding="utf-8"))


@router.get("/api/me")
def admin_me(request: Request) -> dict[str, str | bool | None]:
    return {
        "user": getattr(request.state, "admin_user", None),
        "role": getattr(request.state, "admin_role", "admin"),
        "standard_downloader": (
            getattr(request.state, "admin_role", "admin") == "standard_downloader"
        ),
    }
