# retoor <retoor@molodetz.nl>

import logging
from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse, JSONResponse
from devplacepy.database import get_platform_analytics
from devplacepy.utils import require_admin
from devplacepy.responses import action_result

logger = logging.getLogger(__name__)
router = APIRouter()


@router.get("", response_class=HTMLResponse)
async def admin_index(request: Request):
    require_admin(request)
    return action_result(request, "/admin/users")


@router.get("/analytics")
async def admin_analytics(request: Request, top_n: int = 10):
    require_admin(request)
    return JSONResponse(get_platform_analytics(top_n))
