from datetime import datetime from typing import Optional from pydantic import BaseModel, EmailStr, Field class UserBase(BaseModel): username: str email: EmailStr class UserCreate(UserBase): password: str = Field(..., min_length=8) role: str = "viewer" gatekeeper_groups: list[str] = Field(default_factory=list) class UserUpdate(BaseModel): email: Optional[EmailStr] = None role: Optional[str] = None gatekeeper_groups: Optional[list[str]] = None is_active: Optional[bool] = None class UserInDB(UserBase): id: int role: str gatekeeper_groups: list[str] = Field(default_factory=list) is_active: bool last_login_at: Optional[datetime] created_at: datetime class Config: from_attributes = True class UserResponse(UserBase): id: int role: str gatekeeper_groups: list[str] = Field(default_factory=list) is_active: bool email_verified: bool = False created_at: datetime class Config: from_attributes = True class UserRegister(BaseModel): username: str = Field(..., min_length=3, max_length=50) email: EmailStr password: str = Field(..., min_length=8, max_length=128) class VerifyEmailRequest(BaseModel): email: EmailStr code: str = Field(..., min_length=6, max_length=6) class ResendCodeRequest(BaseModel): email: EmailStr purpose: str = Field(default="register", pattern="^(register|verify_email|reset_password)$") class ForgotPasswordRequest(BaseModel): email: EmailStr class ResetPasswordRequest(BaseModel): email: EmailStr code: str = Field(..., min_length=6, max_length=6) new_password: str = Field(..., min_length=8, max_length=128)