from pydantic import BaseModel, Field, ConfigDict from uuid import UUID from datetime import datetime from typing import List, Optional class UserCreate(BaseModel): username: str = Field(..., pattern=r"^[a-z0-9_]{3,32}$") display_name: str = Field(..., min_length=1, max_length=100) password: str = Field(..., min_length=12, max_length=128) class UserOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: UUID username: str display_name: str created_at: datetime class SessionOut(BaseModel): token: str token_type: str user: UserOut expires_at: datetime class ChatCreate(BaseModel): title: str = Field(..., min_length=1, max_length=100) member_ids: List[UUID] = Field(..., min_items=1, max_items=100) class ChatOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: UUID title: str member_ids: List[UUID] created_at: datetime class MessageCreate(BaseModel): text: str = Field(..., max_length=4000) class MessageOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: UUID chat_id: UUID sender_id: UUID text: str created_at: datetime class MessagePage(BaseModel): items: List[MessageOut] next_cursor: Optional[str] = None