from pydantic import BaseModel, EmailStr, Field, ConfigDict
from datetime import datetime
from app.models.user import UserStatus


class UserCreate(BaseModel):
    email: EmailStr
    username: str = Field(..., min_length=3, max_length=50)
    password: str = Field(..., min_length=8)
    display_name: str | None = None


class UserLogin(BaseModel):
    email: EmailStr
    password: str


class UserUpdate(BaseModel):
    display_name: str | None = None
    avatar_url: str | None = None
    bio: str | None = None


class UserSummary(BaseModel):
    id: int
    username: str
    display_name: str | None
    avatar_url: str | None

    model_config = ConfigDict(from_attributes=True)


class UserResponse(BaseModel):
    id: int
    email: str
    username: str
    display_name: str | None
    avatar_url: str | None
    bio: str | None
    total_bets: int
    wins: int
    losses: int
    win_rate: float
    status: UserStatus
    created_at: datetime

    model_config = ConfigDict(from_attributes=True)


class UserStats(BaseModel):
    total_bets: int
    wins: int
    losses: int
    win_rate: float
    active_bets: int

    model_config = ConfigDict(from_attributes=True)


class TokenResponse(BaseModel):
    access_token: str
    refresh_token: str
    token_type: str = "bearer"


class TokenData(BaseModel):
    user_id: int | None = None
