from datetime import datetime from typing import Optional, Literal, Dict, Any import uuid class Task: def __init__( self, title: str, due_date: str, description: str = "", entity_type: Optional[Literal["client", "prospect", "project", "campaign"]] = None, entity_id: Optional[str] = None, priority: Literal["basse", "normale", "haute"] = "normale", status: Literal["todo", "done", "canceled"] = "todo", id: Optional[str] = None, created_at: Optional[str] = None, completed_at: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None, ): self.id = id or f"tsk_{uuid.uuid4().hex[:8]}" self.title = title self.description = description # due_date: format ISO "YYYY-MM-DD" self.due_date = due_date self.entity_type = entity_type self.entity_id = entity_id self.priority = priority self.status = status now_iso = datetime.utcnow().isoformat() self.created_at = created_at or now_iso self.completed_at = completed_at self.metadata = metadata or {} def to_dict(self) -> Dict[str, Any]: return { "id": self.id, "title": self.title, "description": self.description, "due_date": self.due_date, "entity_type": self.entity_type, "entity_id": self.entity_id, "priority": self.priority, "status": self.status, "created_at": self.created_at, "completed_at": self.completed_at, "metadata": self.metadata, } @staticmethod def from_dict(data: Dict[str, Any]) -> "Task": return Task( id=data.get("id"), title=data.get("title", ""), description=data.get("description", ""), due_date=data.get("due_date", ""), entity_type=data.get("entity_type"), entity_id=data.get("entity_id"), priority=data.get("priority", "normale"), status=data.get("status", "todo"), created_at=data.get("created_at"), completed_at=data.get("completed_at"), metadata=data.get("metadata") or {}, )