from datetime import datetime from typing import Annotated from pydantic import BaseModel, EmailStr, Field from uuid import UUID class Base(BaseModel): model_config = {"from_attributes": True} class UserCreate(Base): first_name:Annotated[str, Field(..., max_length=64,description="first name of the user")] last_name:Annotated[str, Field(...,max_length=64, description="last name of the user")] middle_name:Annotated[str, Field(...,max_length=64, description="middle name of the user")] email:Annotated[EmailStr, Field(...,min_length=5, max_length=255, description="email of the user")] plain_password:Annotated[str, Field(...,min_length=8,max_length=72, description="plain password of the user")] status:Annotated[bool, Field(..., description="status of the user")] permissions:Annotated[list[str], Field(..., description="permissions of the user")] permission_groups:Annotated[list[str], Field(..., description="permissions groups of the user")] class UserOut(Base): first_name:Annotated[str, Field(..., max_length=64,description="first name of the user")] last_name:Annotated[str, Field(..., max_length=64,description="last name of the user")] middle_name:Annotated[str, Field(..., max_length=64, description="middle name of the user")] email:Annotated[EmailStr, Field(...,min_length=5, max_length=255, description="email of the user")] # permissions:Annotated[list[str], Field(..., description="permissions of the user")] # permission_groups:Annotated[list[str], Field(..., description="permissions groups of the user")] class UserOutDB(UserOut): id:Annotated[UUID, Field(..., description="Id of the user")] status:Annotated[bool, Field(..., description="status of the user")] hashed_password:Annotated[str, Field(..., description="hashed password of the user")] class UserUpdate(Base): first_name:Annotated[str|None, Field(None, max_length=64, description="first name of the user")] last_name:Annotated[str|None, Field(None, max_length=64,description="last name of the user")] middle_name:Annotated[str|None, Field(None, max_length=64,description="middle name of the user")] email:Annotated[EmailStr|None, Field(None, min_length=5, max_length=255, description="email of the user")] status:Annotated[bool|None, Field(None, description="status of the user")] permissions:Annotated[list[str]|None, Field(None, description="permissions of the user")] permission_groups:Annotated[list[str]|None, Field(None, description="permissions groups of the user")] class PermissionsCreate(Base): permission:Annotated[str, Field(..., max_length=30, description="permission name")] class PermissionsOut(Base): permission:Annotated[str, Field(..., max_length=30, description="permission name")] class PermissionsGroupsCreate(Base): group:Annotated[str, Field(..., max_length=255, description="group name for the permissions")] class PermissionsGroupsOut(Base): group:Annotated[str, Field(..., max_length=255, description="group name for the permissions")] class RefreshTokensCreate(Base): user_id:Annotated[UUID, Field(..., description="foreign key for the user")] token_hash:Annotated[str, Field(...,max_length=255, description="token hash")] device_info:Annotated[str, Field(...,max_length=255, description="User device info")] ip_address:Annotated[str, Field(...,max_length=45, description="ip v4/v6 of the user")] is_revoked:Annotated[bool|None, Field(None, description="revoke token if logout was made")] expires_at:Annotated[datetime, Field(..., description="when token is going to be expired")] class RefreshTokensOut(Base): user_id:Annotated[UUID, Field(..., description="foreign key for the user")] token_hash:Annotated[str, Field(..., max_length=255,description="token hash")] device_info:Annotated[str, Field(..., max_length=255, description="User device info")] ip_address:Annotated[str, Field(...,max_length=45, description="ip v4/v6 of the user")] is_revoked:Annotated[bool|None, Field(None, description="revoke token if logout was made")] expires_at:Annotated[datetime, Field(..., description="when token is going to be expired")]