from fastapi import APIRouter, HTTPException, Depends
from pydantic import BaseModel
from fastapi.security import OAuth2PasswordRequestForm
from app.core.security import authenticate_user, create_access_token
from app.core.security import verify_token
from app.services.ranking_service import get_ranking_data


router = APIRouter()

@router.get("/ranking")
def get_ranking( user_data: dict = Depends(verify_token)):
    email = user_data.get("sub")
    if not email:
        raise HTTPException(status_code=401, detail="Usuari no identificat")
    
    results = get_ranking_data()
    return {"ranking": results}