"""
Schema definitions for leaderboard API.

This module provides Pydantic models for leaderboard-related responses
and requests.
"""

from datetime import datetime
from pydantic import BaseModel, Field


class LeaderboardEntry(BaseModel):
    """Represents a single entry in the leaderboard."""
    user_id: int
    username: str | None = None
    accuracy: float = Field(..., ge=0, le=100, description="Accuracy percentage (0-100)")
    predictions_count: int = Field(..., ge=0, description="Total number of predictions viewed")

    class Config:
        json_schema_extra = {
            "example": {
                "user_id": 1,
                "username": "JohnDoe",
                "accuracy": 85.5,
                "predictions_count": 42
            }
        }


class PersonalRankData(BaseModel):
    """Represents personal rank data for the current user."""
    rank: int = Field(..., ge=1, description="User's rank in the leaderboard")
    accuracy: float = Field(..., ge=0, le=100, description="User's accuracy percentage")
    predictions_count: int = Field(..., ge=0, description="User's total predictions viewed")

    class Config:
        json_schema_extra = {
            "example": {
                "rank": 42,
                "accuracy": 75.5,
                "predictions_count": 25
            }
        }


class LeaderboardResponse(BaseModel):
    """Response model for leaderboard endpoint."""
    data: list[LeaderboardEntry]
    personal_data: PersonalRankData | None = None
    meta: dict

    class Config:
        json_schema_extra = {
            "example": {
                "data": [
                    {
                        "user_id": 1,
                        "username": "JohnDoe",
                        "accuracy": 95.5,
                        "predictions_count": 100
                    },
                    {
                        "user_id": 2,
                        "username": "JaneSmith",
                        "accuracy": 90.0,
                        "predictions_count": 85
                    }
                ],
                "personal_data": {
                    "rank": 42,
                    "accuracy": 75.5,
                    "predictions_count": 25
                },
                "meta": {
                    "total": 2,
                    "limit": 100,
                    "timestamp": "2026-01-18T10:30:00Z",
                    "version": "v1"
                }
            }
        }
