import uuid
from datetime import datetime
from typing import Any, Optional

from pydantic import BaseModel, ConfigDict


# ── Badge ───────────────────────────────────────────────────────────────────

class BadgeResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: uuid.UUID
    name: str
    description: Optional[str] = None
    icon: Optional[str] = None
    category: Optional[str] = None
    condition_type: str
    condition_value: dict[str, Any]
    sort_order: int


class UserBadgeResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    badge: BadgeResponse
    awarded_at: datetime


# ── Level ───────────────────────────────────────────────────────────────────

class LevelResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: uuid.UUID
    name: str
    min_xp: int
    color: Optional[str] = None
    icon: Optional[str] = None
    sort_order: int


class LevelProgress(BaseModel):
    current_level: LevelResponse
    next_level: Optional[LevelResponse] = None
    xp_to_next: int
    progress_pct: float


# ── Activity Feed ───────────────────────────────────────────────────────────

class ActivityFeedItem(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: uuid.UUID
    user_id: Optional[uuid.UUID] = None
    user_name: Optional[str] = None
    event_type: str
    event_data: Optional[dict[str, Any]] = None
    created_at: datetime
