from pydantic import BaseModel, Field, field_validator from pydantic_settings import BaseSettings, SettingsConfigDict from pydantic.types import StringConstraints from typing_extensions import Annotated from typing import Optional import re NameStr = Annotated[ str, StringConstraints( min_length=2, max_length=50, pattern=r'^[A-Za-zА-ЯЁа-яё]+$' ) ] class UserAccess(BaseModel): code:str = Field(...,min_length=6,max_length=6, description="Code of the guest") class Token(BaseModel): access_token: str token_type: str class UserOut(BaseModel): name: NameStr = Field(..., description="Name of the guest") surname: NameStr = Field(..., description="Surname of the guest") class UserUpdate(BaseModel): code: Optional[str] = Field(None, min_length=6, max_length=6, description="Code of the guest") name: Optional[NameStr] = Field(None, description="Name of the guest") middlename: Optional[NameStr] = Field(None, description="Middlename of the guest") surname: Optional[NameStr] = Field(None, description="Surname of the guest") text_field: Optional[str] = Field(None, max_length=500, description="what the guest wants") activated: Optional[bool] = Field(None, description="activation of the guest") type_of_food: Optional[str] = Field(None, description="meat or fish") types_of_alco: Optional[str] = Field(None, description="types of alco") class UserCreate(UserUpdate): code: str = Field(..., min_length=6, max_length=6, description="Code of the guest") admin:bool = Field(False, description="Admin privilegies") class Settings(BaseSettings): DIR:str PORT:int SECRET_KEY:str ALGORITHM:str ACCESS_TOKEN_EXPIRE_SECONDS:int model_config = SettingsConfigDict( env_file=".env", env_file_encoding="utf-8" ) settings = Settings()