SuiteConsultance/modules/email/draft.py
2025-09-20 13:18:04 +02:00

70 lines
2.3 KiB
Python

from typing import Optional, Dict, Any
from datetime import datetime
import uuid
class EmailDraft:
"""
Représente un brouillon d'email généré automatiquement.
Stockage fichier: Data/email_drafts/<id>.json
"""
def __init__(
self,
prospect_id: str,
to_email: str,
subject: str,
content: str,
status: str = "draft", # draft | sent | failed
template_id: Optional[str] = None,
task_id: Optional[str] = None,
id: Optional[str] = None,
created_at: Optional[str] = None,
sent_at: Optional[str] = None,
error_message: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
):
self.id = id or f"ed_{uuid.uuid4().hex[:10]}"
self.prospect_id = prospect_id
self.to_email = to_email
self.subject = subject
self.content = content
self.status = status
self.template_id = template_id
self.task_id = task_id
self.created_at = created_at or datetime.utcnow().isoformat()
self.sent_at = sent_at
self.error_message = error_message
self.metadata = metadata or {}
def to_dict(self) -> Dict[str, Any]:
return {
"id": self.id,
"prospect_id": self.prospect_id,
"to_email": self.to_email,
"subject": self.subject,
"content": self.content,
"status": self.status,
"template_id": self.template_id,
"task_id": self.task_id,
"created_at": self.created_at,
"sent_at": self.sent_at,
"error_message": self.error_message,
"metadata": self.metadata,
}
@staticmethod
def from_dict(data: Dict[str, Any]) -> "EmailDraft":
return EmailDraft(
id=data.get("id"),
prospect_id=data.get("prospect_id", ""),
to_email=data.get("to_email", ""),
subject=data.get("subject", ""),
content=data.get("content", ""),
status=data.get("status", "draft"),
template_id=data.get("template_id"),
task_id=data.get("task_id"),
created_at=data.get("created_at"),
sent_at=data.get("sent_at"),
error_message=data.get("error_message"),
metadata=data.get("metadata") or {},
)