from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app.api.deps import require_roles
from app.db.session import get_db
from app.models import AdminUser, Certificate, ImportBatch, Learner

router = APIRouter()


@router.get("/summary")
def get_summary(
    db: Session = Depends(get_db),
    _: AdminUser = Depends(require_roles("system_admin", "certificate_admin", "readonly")),
) -> dict[str, int]:
    return {
        "learner_count": db.query(Learner).count(),
        "certificate_count": db.query(Certificate).count(),
        "valid_certificate_count": db.query(Certificate).filter(Certificate.status == "valid").count(),
        "voided_certificate_count": db.query(Certificate).filter(Certificate.status == "voided").count(),
        "recent_import_count": db.query(ImportBatch).count(),
    }
