115 lines
4.5 KiB
Python
115 lines
4.5 KiB
Python
"""
|
|
Service Management model classes for the service management system.
|
|
Updated to match the Entity Relation Diagram structure.
|
|
"""
|
|
|
|
from pydantic import BaseModel, Field
|
|
from typing import List, Dict, Any, Optional, Union
|
|
from datetime import datetime
|
|
import uuid
|
|
|
|
# Import for label registration
|
|
from modules.shared.attributeUtils import register_model_labels, ModelMixin
|
|
|
|
# CORE MODELS
|
|
|
|
class FileItem(BaseModel, ModelMixin):
|
|
"""Data model for a file item"""
|
|
id: str = Field(default_factory=lambda: str(uuid.uuid4()), description="Primary key")
|
|
mandateId: str = Field(description="ID of the mandate this file belongs to")
|
|
filename: str = Field(description="Name of the file")
|
|
mimeType: str = Field(description="MIME type of the file")
|
|
fileHash: str = Field(description="Hash of the file")
|
|
fileSize: int = Field(description="Size of the file in bytes")
|
|
creationDate: str = Field(default_factory=lambda: datetime.now().isoformat(), description="Date when the file was created")
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
"""Convert model to dictionary with proper datetime handling"""
|
|
data = super().to_dict()
|
|
if isinstance(data.get("creationDate"), datetime):
|
|
data["creationDate"] = data["creationDate"].isoformat()
|
|
return data
|
|
|
|
# Register labels for FileItem
|
|
register_model_labels(
|
|
"FileItem",
|
|
{"en": "File Item", "fr": "Élément de fichier"},
|
|
{
|
|
"id": {"en": "ID", "fr": "ID"},
|
|
"mandateId": {"en": "Mandate ID", "fr": "ID du mandat"},
|
|
"filename": {"en": "Filename", "fr": "Nom de fichier"},
|
|
"mimeType": {"en": "MIME Type", "fr": "Type MIME"},
|
|
"fileHash": {"en": "File Hash", "fr": "Hash du fichier"},
|
|
"fileSize": {"en": "File Size", "fr": "Taille du fichier"},
|
|
"creationDate": {"en": "Creation Date", "fr": "Date de création"}
|
|
}
|
|
)
|
|
|
|
class FilePreview(BaseModel, ModelMixin):
|
|
"""Data model for file preview"""
|
|
content: Union[str, bytes] = Field(description="File content (text or binary)")
|
|
mimeType: str = Field(description="MIME type of the file")
|
|
filename: str = Field(description="Original filename")
|
|
isText: bool = Field(description="Whether the content is text (True) or binary (False)")
|
|
encoding: Optional[str] = Field(None, description="Text encoding if content is text")
|
|
size: int = Field(description="Size of the content in bytes")
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
"""Convert model to dictionary with proper content handling"""
|
|
data = super().to_dict()
|
|
# Convert bytes to base64 string if content is binary
|
|
if isinstance(data.get("content"), bytes):
|
|
import base64
|
|
data["content"] = base64.b64encode(data["content"]).decode('utf-8')
|
|
return data
|
|
|
|
# Register labels for FilePreview
|
|
register_model_labels(
|
|
"FilePreview",
|
|
{"en": "File Preview", "fr": "Aperçu du fichier"},
|
|
{
|
|
"content": {"en": "Content", "fr": "Contenu"},
|
|
"mimeType": {"en": "MIME Type", "fr": "Type MIME"},
|
|
"filename": {"en": "Filename", "fr": "Nom de fichier"},
|
|
"isText": {"en": "Is Text", "fr": "Est du texte"},
|
|
"encoding": {"en": "Encoding", "fr": "Encodage"},
|
|
"size": {"en": "Size", "fr": "Taille"}
|
|
}
|
|
)
|
|
|
|
class FileData(BaseModel, ModelMixin):
|
|
"""Data model for file data"""
|
|
id: str = Field(default_factory=lambda: str(uuid.uuid4()), description="Primary key")
|
|
data: str = Field(description="File data content")
|
|
base64Encoded: bool = Field(description="Whether the data is base64 encoded")
|
|
|
|
# Register labels for FileData
|
|
register_model_labels(
|
|
"FileData",
|
|
{"en": "File Data", "fr": "Données de fichier"},
|
|
{
|
|
"id": {"en": "ID", "fr": "ID"},
|
|
"data": {"en": "Data", "fr": "Données"},
|
|
"base64Encoded": {"en": "Base64 Encoded", "fr": "Encodé en Base64"}
|
|
}
|
|
)
|
|
|
|
class Prompt(BaseModel, ModelMixin):
|
|
"""Data model for a prompt"""
|
|
id: str = Field(default_factory=lambda: str(uuid.uuid4()), description="Primary key")
|
|
mandateId: str = Field(description="ID of the mandate this prompt belongs to")
|
|
content: str = Field(description="Content of the prompt")
|
|
name: str = Field(description="Name of the prompt")
|
|
|
|
# Register labels for Prompt
|
|
register_model_labels(
|
|
"Prompt",
|
|
{"en": "Prompt", "fr": "Invite"},
|
|
{
|
|
"id": {"en": "ID", "fr": "ID"},
|
|
"mandateId": {"en": "Mandate ID", "fr": "ID du mandat"},
|
|
"content": {"en": "Content", "fr": "Contenu"},
|
|
"name": {"en": "Name", "fr": "Nom"}
|
|
}
|
|
)
|
|
|