""" Data models for the gateway system. """ from pydantic import BaseModel, Field from typing import List, Dict, Any, Optional from datetime import datetime class Label(BaseModel): """Label for an attribute or a class with support for multiple languages""" default: str translations: Dict[str, str] = {} def getLabel(self, language: str = None): """Returns the label in the specified language, or the default value if not available""" if language and language in self.translations: return self.translations[language] return self.default class Mandate(BaseModel): """Data model for a mandate""" id: int = Field(description="Unique ID of the mandate") name: str = Field(description="Name of the mandate") language: str = Field(description="Default language of the mandate") label: Label = Field( default=Label(default="Mandate", translations={"en": "Mandate", "fr": "Mandat"}), description="Label for the class" ) # Labels for attributes fieldLabels: Dict[str, Label] = { "id": Label(default="ID", translations={}), "name": Label(default="Name of the mandate", translations={"en": "Mandate name", "fr": "Nom du mandat"}), "language": Label(default="Language", translations={"en": "Language", "fr": "Langue"}) } class User(BaseModel): """Data model for a user""" id: int = Field(description="Unique ID of the user") mandateId: int = Field(description="ID of the associated mandate") username: str = Field(description="Username for login") email: Optional[str] = Field(None, description="Email address of the user") fullName: Optional[str] = Field(None, description="Full name of the user") language: str = Field(description="Preferred language of the user") disabled: Optional[bool] = Field(False, description="Indicates whether the user is disabled") privilege: str = Field(description="Permission level") #sysadmin,admin,user label: Label = Field( default=Label(default="User", translations={"en": "User", "fr": "Utilisateur"}), description="Label for the class" ) # Labels for attributes fieldLabels: Dict[str, Label] = { "id": Label(default="ID", translations={}), "mandateId": Label(default="Mandate ID", translations={"en": "Mandate ID", "fr": "ID de mandat"}), "username": Label(default="Username", translations={"en": "Username", "fr": "Nom d'utilisateur"}), "email": Label(default="Email", translations={"en": "Email", "fr": "E-mail"}), "fullName": Label(default="Full name", translations={"en": "Full name", "fr": "Nom complet"}), "language": Label(default="Language", translations={"en": "Language", "fr": "Langue"}), "disabled": Label(default="Disabled", translations={"en": "Disabled", "fr": "Désactivé"}), "privilege": Label(default="Permission level", translations={"en": "Access level", "fr": "Niveau d'accès"}), } class UserInDB(User): """Extended user class with password hash""" hashedPassword: str = Field(description="Hash of the user password") label: Label = Field( default=Label(default="User Access", translations={"en": "User Access", "fr": "Accès de l'utilisateur"}), description="Label for the class" ) # Additional label for the password field fieldLabels: Dict[str, Label] = { "hashedPassword": Label(default="Password hash", translations={"en": "Password hash", "fr": "Hachage de mot de passe"}) } class Token(BaseModel): """Data model for an authentication token""" accessToken: str = Field(description="The issued access token") tokenType: str = Field(description="Type of token (usually 'bearer')") label: Label = Field( default=Label(default="Token", translations={"en": "Token", "fr": "Jeton"}), description="Label for the class" ) # Labels for attributes fieldLabels: Dict[str, Label] = { "accessToken": Label(default="Access token", translations={"en": "Access token", "fr": "Jeton d'accès"}), "tokenType": Label(default="Token type", translations={"en": "Token type", "fr": "Type de jeton"}) } class TokenData(BaseModel): """Data for token decoding and validation""" username: Optional[str] = None mandateId: Optional[int] = None exp: Optional[datetime] = None