from datetime import date from typing import Literal from modules.crm.prospect_handler import ProspectHandler def categorize(score: int) -> Literal["Froid", "Tiède", "Chaud"]: if score is None: score = 0 if score >= 50: return "Chaud" if score >= 20: return "Tiède" return "Froid" def adjust_score(prospect_id: str, delta: int) -> int: """ Ajuste le score d'un prospect et met à jour la dernière interaction. Retourne le score à jour. """ handler = ProspectHandler() p = handler.get_prospect_by_id(prospect_id) if not p: return 0 try: current = int(getattr(p, "score", 0) or 0) except Exception: current = 0 new_score = max(0, current + int(delta)) setattr(p, "score", new_score) setattr(p, "last_interaction", date.today().isoformat()) # On ne change pas le statut ici, sauf règle spécifique (reply) handler.update_prospect(p) return new_score def adjust_score_for_event(prospect_id: str, event: Literal["open", "click", "reply"]) -> int: if event == "open": return adjust_score(prospect_id, 10) if event == "click": return adjust_score(prospect_id, 20) if event == "reply": score = adjust_score(prospect_id, 30) # Règle: un reply passe le prospect en statut "Chaud" handler = ProspectHandler() p = handler.get_prospect_by_id(prospect_id) if p: p.status = "Chaud" handler.update_prospect(p) return score return adjust_score(prospect_id, 0)