from collections.abc import AsyncGenerator
from typing import Annotated

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

from src.db.database import get_db
from src.schemas import StatsResponse
from src.services import StatsService

router = APIRouter()


async def get_stats_service(
    db: Annotated[AsyncSession, Depends(get_db)],
) -> AsyncGenerator[StatsService, None]:
    """Dependency for StatsService."""
    yield StatsService(db)


@router.get("", response_model=StatsResponse)
async def get_stats(
    service: Annotated[StatsService, Depends(get_stats_service)],
) -> StatsResponse:
    """Get question counts by difficulty, category, and pattern."""
    return await service.get_stats()
