Source code for cadrumo.domain.deadlines.fact_context
"""Typed governed-fact resolution context for deadline consequences.The deadline domain receives authority and both temporal coordinates from itsapplication composition boundary. It does not open the bundled registry on adomain-method call: the caller must state the filing and submission dates thatselect each fact."""from__future__importannotationsfromdataclassesimportdataclassfromdatetimeimportdatefromdecimalimportDecimalfrom..calculations.registry.errorsimportRegistryValidationErrorfrom..calculations.registry.facts.resolutionimport(MappingFactQuery,ResolvedMappingFact,ResolvedScalarFact,ScalarFactQuery,)from..calculations.registry.governed_fact_scopeimportGovernedFactSourcefrom..calculations.registry.schema_baseimportDateAxis_DEADLINE_FACT_DATE_AXIS_MAPPING_FACT_ID="deadline-fact-date-axis-mapping"
[docs]@dataclass(frozen=True,slots=True)classDeadlineFactResolutionContext:"""Authority and explicit filing/submission coordinates for deadline facts."""authority:GovernedFactSourcefiling_period:datesubmission_date:date
[docs]defdecimal(self,fact_id:str)->Decimal:"""Resolve a Decimal-valued deadline scalar while retaining provenance."""resolved=self.resolved_scalar(fact_id)ifnotisinstance(resolved.payload.value,Decimal):raiseRegistryValidationError(f"deadline fact {fact_id!r} must resolve to a Decimal")returnresolved.payload.value
[docs]definteger(self,fact_id:str)->int:"""Resolve an integer-valued deadline scalar while retaining provenance."""resolved=self.resolved_scalar(fact_id)iftype(resolved.payload.value)isnotint:raiseRegistryValidationError(f"deadline fact {fact_id!r} must resolve to an integer")returnresolved.payload.value
[docs]defmapping_decimal(self,fact_id:str,key:int)->Decimal:"""Resolve one exact Decimal entry from a governed mapping fact. A missing key is an unpublished legal coordinate, not permission to substitute the most recent value. """resolved=self.resolved_mapping(fact_id)forentryinresolved.payload.entries:ifentry.key==key:ifnotisinstance(entry.value,Decimal):raiseRegistryValidationError(f"deadline mapping {fact_id!r} entry {key!r} must be Decimal")returnentry.valueraiseRegistryValidationError(f"deadline mapping {fact_id!r} has no entry for {key!r}")
[docs]defresolved_scalar(self,fact_id:str)->ResolvedScalarFact:"""Resolve a scalar on the fact's declared temporal axis."""axis=self._date_axis(fact_id)resolved=self.authority.resolve_governed_fact(ScalarFactQuery(fact_id=fact_id,date_axis=axis,effective_date=self._coordinate(axis)))ifnotisinstance(resolved,ResolvedScalarFact):raiseRegistryValidationError(f"deadline fact {fact_id!r} must resolve to a scalar")returnresolved
[docs]defresolved_mapping(self,fact_id:str)->ResolvedMappingFact:"""Resolve a mapping on the fact's declared temporal axis."""axis=self._date_axis(fact_id)resolved=self.authority.resolve_governed_fact(MappingFactQuery(fact_id=fact_id,date_axis=axis,effective_date=self._coordinate(axis)))ifnotisinstance(resolved,ResolvedMappingFact):raiseRegistryValidationError(f"deadline fact {fact_id!r} must resolve to a mapping")returnresolved
def_date_axis(self,fact_id:str)->DateAxis:resolved=self.authority.resolve_governed_fact(MappingFactQuery(fact_id=_DEADLINE_FACT_DATE_AXIS_MAPPING_FACT_ID,date_axis=DateAxis.FILING_PERIOD,effective_date=self.filing_period,),)ifnotisinstance(resolved,ResolvedMappingFact):raiseRegistryValidationError(f"deadline fact {_DEADLINE_FACT_DATE_AXIS_MAPPING_FACT_ID!r} must resolve to a mapping",)forentryinresolved.payload.entries:ifentry.key!=fact_id:continueifnotisinstance(entry.value,str):raiseRegistryValidationError(f"deadline fact {fact_id!r} date axis must be a string",)try:returnDateAxis(entry.value)exceptValueErrorasexc:raiseRegistryValidationError(f"deadline fact {fact_id!r} has unknown date axis {entry.value!r}",)fromexcraiseRegistryValidationError(f"unregistered deadline governed fact {fact_id!r}")def_coordinate(self,axis:DateAxis)->date:ifaxisisDateAxis.FILING_PERIOD:returnself.filing_periodifaxisisDateAxis.SUBMISSION_DATE:returnself.submission_dateraiseRegistryValidationError(f"deadline fact axis {axis.value!r} has no configured coordinate")