from datetime import datetime from typing import Optional from pydantic import BaseModel, Field, EmailStr, ConfigDict class User(BaseModel): """User data model for authentication and authorization""" model_config = ConfigDict( populate_by_name=True, json_schema_extra={ "example": { "username": "johndoe", "email": "johndoe@example.com", "full_name": "John Doe", "role": "editor", "disabled": False } } ) id: Optional[str] = Field(default=None, alias="_id") username: str = Field(..., min_length=3, max_length=50) email: EmailStr = Field(...) hashed_password: str = Field(...) full_name: str = Field(..., min_length=1, max_length=100) role: str = Field(default="viewer", description="Role: admin, editor, viewer") disabled: bool = Field(default=False) created_at: datetime = Field(default_factory=datetime.utcnow) last_login: Optional[datetime] = None