mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
A trigger message validates the fields each fired Abri flow needs 🟩
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
c281456164
commit
8daaa0974d
1 changed files with 21 additions and 5 deletions
|
|
@ -7,22 +7,38 @@ visibility surface.
|
|||
"""
|
||||
|
||||
from datetime import date
|
||||
from typing import Any, List, Literal, Optional
|
||||
from typing import Dict, List, Literal, Optional, Tuple
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||
|
||||
AbriFlow = Literal["amend_job", "log_job", "sync_tenant_data"]
|
||||
|
||||
# The deal fields each flow reads; hubspot_deal_id is always required.
|
||||
_FIELDS_BY_FLOW: Dict[AbriFlow, Tuple[str, ...]] = {
|
||||
"amend_job": ("confirmed_survey_date",),
|
||||
"log_job": ("place_ref", "deal_name", "confirmed_survey_date"),
|
||||
"sync_tenant_data": ("place_ref",),
|
||||
}
|
||||
|
||||
|
||||
class AbriTriggerRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
hubspot_deal_id: str
|
||||
flows: List[AbriFlow]
|
||||
flows: List[AbriFlow] = Field(min_length=1)
|
||||
place_ref: Optional[str] = None
|
||||
deal_name: Optional[str] = None
|
||||
confirmed_survey_date: Optional[date] = None
|
||||
confirmed_survey_time: Optional[str] = None
|
||||
|
||||
def model_post_init(self, __context: Any) -> None:
|
||||
raise NotImplementedError
|
||||
@model_validator(mode="after")
|
||||
def _each_fired_flow_has_its_fields(self) -> "AbriTriggerRequest":
|
||||
missing = [
|
||||
f"flow {flow} requires {field}"
|
||||
for flow in self.flows
|
||||
for field in _FIELDS_BY_FLOW[flow]
|
||||
if getattr(self, field) is None
|
||||
]
|
||||
if missing:
|
||||
raise ValueError("; ".join(missing))
|
||||
return self
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue