feat: enforce conditional payment validation in schema

This commit is contained in:
rsxri 2026-01-06 18:10:55 +00:00
parent 8f1e12bac9
commit bb61418c79

View file

@ -1,6 +1,6 @@
from typing import Literal, Optional
from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, model_validator
class DocumentInput(BaseModel):
@ -13,4 +13,15 @@ class DocumentInput(BaseModel):
fixed_fee_gbp: Optional[float] = Field(None, gt=0)
include_confidentiality: bool = False
governing_law: str
governing_law: str
@model_validator(mode="after")
def check_payment_fields(self):
# enforce conditional reqs cleanly
if self.payment_type == "hourly" and self.hourly_rate_gbp is None:
raise ValueError("hourly_rate_gbp is required when payment_type is 'hourly'")
if self.payment_type == "fixed" and self.fixed_fee_gbp is None:
raise ValueError("fixed_fee_gbp is required when payment_type is 'fixed'")
return self