from datetime import datetime
from pydantic import BaseModel, Field, HttpUrl

from app.schemas.user import UserPublic


class GameBase(BaseModel):
    title: str = Field(..., min_length=1, max_length=100)
    download_url: str = Field(..., min_length=1)
    genre: str | None = Field(None, max_length=50)


class GameCreate(GameBase):
    cover_url: str | None = None


class GameUpdate(BaseModel):
    title: str | None = Field(None, min_length=1, max_length=100)
    download_url: str | None = None
    genre: str | None = None


class GameShort(BaseModel):
    id: int
    title: str
    cover_url: str | None = None

    class Config:
        from_attributes = True


class GameResponse(GameBase):
    id: int
    cover_url: str | None = None
    status: str = "pending"
    proposed_by: UserPublic | None = None
    approved_by: UserPublic | None = None
    challenges_count: int = 0
    created_at: datetime

    class Config:
        from_attributes = True
