""" Pydantic schemas for authentication and admin endpoints. """ from datetime import datetime from typing import Optional from pydantic import BaseModel, Field class RegisterIn(BaseModel): """Request schema for user registration.""" username: str = Field( ..., min_length=3, max_length=60, pattern=r"^[a-zA-Z0-9_]{3,20}$", description="Username (alphanumeric and underscores only, 3-20 chars)" ) password: str = Field(..., min_length=8, max_length=128, description="Password") class LoginIn(BaseModel): """Request schema for user login.""" username: str = Field(..., min_length=3, max_length=60, description="Username") password: str = Field(..., min_length=8, max_length=128, description="Password") class TokenOut(BaseModel): """Response schema for token generation (login/register).""" token: str username: str is_admin: bool = False class MeOut(BaseModel): """Response schema for current user info.""" username: str is_admin: bool = False # Article schemas class ArticleBase(BaseModel): """Base article schema with common fields.""" title: str = Field(..., min_length=1, max_length=300) url: str = Field("", max_length=500) content: str = Field(..., description="Rich text content") points: int = Field(0, ge=0, le=1000000) class ArticleIn(ArticleBase): """Schema for creating/updating articles.""" pass class ArticleOut(ArticleBase): """Schema for article output data.""" id: int author_id: int created_at: datetime class Config: from_attributes = True class ArticleAdminIn(ArticleBase): """Schema for admin create/update operations.""" title: str = Field(..., min_length=1, max_length=300) url: str = Field("", max_length=500) content: str = Field(..., description="Rich text content") points: int = Field(0, ge=0, le=1000000) class ArticleAdminOut(ArticleBase): """Schema for admin article output data.""" id: int author_id: int created_at: datetime class Config: from_attributes = True # Pagination response schema class PaginatedResponse(BaseModel): """Standard pagination response structure.""" items: list[ArticleAdminOut] total: int page: int page_size: int total_pages: int