"""Public stats endpoints for Chrysopedia."""

import logging

from fastapi import APIRouter, Depends
from sqlalchemy import func, select
from sqlalchemy.ext.asyncio import AsyncSession

from database import get_session
from models import Creator, TechniquePage

logger = logging.getLogger("chrysopedia.stats")

router = APIRouter(tags=["stats"])


@router.get("/stats")
async def get_stats(db: AsyncSession = Depends(get_session)) -> dict:
    """Return aggregate counts for the knowledge base."""
    technique_count = await db.scalar(
        select(func.count()).select_from(TechniquePage)
    )
    creator_count = await db.scalar(
        select(func.count()).select_from(Creator)
    )
    return {
        "technique_count": technique_count or 0,
        "creator_count": creator_count or 0,
    }
