import uuid from pydantic import BaseModel, ConfigDict, EmailStr, Field, model_validator from app.common.enums import Role class UserCreate(BaseModel): email: EmailStr password: str = Field(min_length=8, max_length=128) full_name: str = Field(min_length=2, max_length=200) employee_code: str = Field(min_length=1, max_length=50) role: Role phone: str | None = Field(default=None, max_length=20) #: Required for MR, forbidden for every other role (R4/R8). headquarters_id: uuid.UUID | None = None @model_validator(mode="after") def check_hq_matches_role(self): if self.role == Role.MR and self.headquarters_id is None: raise ValueError("headquarters_id is required for an MR") if self.role != Role.MR and self.headquarters_id is not None: raise ValueError("headquarters_id may only be set for an MR") return self class UserUpdate(BaseModel): full_name: str | None = Field(default=None, min_length=2, max_length=200) #: Sign-in credentials. Admin-only (the whole endpoint is); changing them is audited. email: EmailStr | None = None employee_code: str | None = Field(default=None, min_length=1, max_length=50) #: A new password. Signs the user out everywhere and clears a lockout. password: str | None = Field(default=None, min_length=8, max_length=128) phone: str | None = Field(default=None, max_length=20) headquarters_id: uuid.UUID | None = None is_active: bool | None = None class UserRead(BaseModel): model_config = ConfigDict(from_attributes=True) id: uuid.UUID email: str full_name: str employee_code: str role: Role phone: str | None headquarters_id: uuid.UUID | None is_active: bool class MyProfile(BaseModel): """S4 — the MR profile screen. Includes the DERIVED reporting Area Manager.""" id: uuid.UUID full_name: str employee_code: str email: str role: Role phone: str | None headquarters_id: uuid.UUID | None headquarters_code: str | None headquarters_name: str | None reporting_manager_id: uuid.UUID | None reporting_manager_name: str | None