"""Dashboard API endpoints.""" from typing import Annotated, Any from fastapi import APIRouter, Depends, HTTPException, Query, status from app.core.dependencies import get_current_user, get_dashboard_service from app.models.user import User from app.services.dashboard import DashboardService router = APIRouter(prefix="/dashboard", tags=["dashboard"]) @router.get("/soundboard-statistics") async def get_soundboard_statistics( _current_user: Annotated[User, Depends(get_current_user)], dashboard_service: Annotated[DashboardService, Depends(get_dashboard_service)], ) -> dict[str, Any]: """Get soundboard statistics.""" try: return await dashboard_service.get_soundboard_statistics() except Exception as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to fetch soundboard statistics: {e!s}", ) from e @router.get("/track-statistics") async def get_track_statistics( _current_user: Annotated[User, Depends(get_current_user)], dashboard_service: Annotated[DashboardService, Depends(get_dashboard_service)], ) -> dict[str, Any]: """Get track statistics.""" try: return await dashboard_service.get_track_statistics() except Exception as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to fetch track statistics: {e!s}", ) from e @router.get("/tts-statistics") async def get_tts_statistics( _current_user: Annotated[User, Depends(get_current_user)], dashboard_service: Annotated[DashboardService, Depends(get_dashboard_service)], ) -> dict[str, Any]: """Get TTS statistics.""" try: return await dashboard_service.get_tts_statistics() except Exception as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to fetch TTS statistics: {e!s}", ) from e @router.get("/top-sounds") async def get_top_sounds( _current_user: Annotated[User, Depends(get_current_user)], dashboard_service: Annotated[DashboardService, Depends(get_dashboard_service)], sound_type: Annotated[ str, Query(description="Sound type filter (SDB, TTS, EXT, or 'all')"), ], period: Annotated[ str, Query( description="Time period (today, 1_day, 1_week, 1_month, 1_year, all_time)", ), ] = "all_time", limit: Annotated[ int, Query(description="Number of top sounds to return", ge=1, le=100), ] = 10, ) -> list[dict[str, Any]]: """Get top sounds by play count for a specific period.""" try: return await dashboard_service.get_top_sounds( sound_type=sound_type, period=period, limit=limit, ) except Exception as e: raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Failed to fetch top sounds: {e!s}", ) from e