"""admin 数据大盘(只读聚合)。"""
from __future__ import annotations

from datetime import date

from fastapi import APIRouter, Depends, Query

from app.admin.deps import AdminDb, get_current_admin
from app.admin.repositories import stats
from app.admin.schemas.dashboard import DashboardOverview

router = APIRouter(
    prefix="/admin/api/stats",
    tags=["admin-stats"],
    dependencies=[Depends(get_current_admin)],
)


@router.get("/overview", response_model=DashboardOverview, summary="大盘核心指标")
def overview(
    db: AdminDb,
    date_from: date | None = Query(None, description="北京时间自然日起始日 YYYY-MM-DD"),
    date_to: date | None = Query(None, description="北京时间自然日结束日 YYYY-MM-DD"),
) -> DashboardOverview:
    return DashboardOverview.model_validate(
        stats.dashboard_overview(db, date_from=date_from, date_to=date_to)
    )
