Source code for cadrumo.domain.submission.protocols
"""Narrow Protocol ports for the submission engine.The submission engine is composed of read-only sub-systems that thetest suite exercises with concrete, hand-rolled Protocol-conformingclasses (no mocks, no patches). Each Protocol declares only thesurface the engine actually consumes, decoupling submission from thericher surfaces of its sibling subpackages.- :class:`AuthProviderProbe` — narrow auth-provider surface for the preflight gate.- :class:`DeadlineWindowChecker` — narrow surface over :mod:`cadrumo.domain.deadlines` used by preflight.- :class:`ModeloFindingLike` / :class:`ModeloDraftLike` — narrow filing draft surfaces; :class:`domain.filing.schema.ModeloDraft` structurally conforms to :class:`ModeloDraftLike`.- :class:`SubmissionRepositoryProtocol` — the read-side persistence port.Every declaration here is a ``runtime_checkable`` ``Protocol``. The recordtypes these ports carry — :class:`ModeloDraftStatus` among them — livebeside the other submission records in:mod:`cadrumo.domain.submission.models`. Finding entries are typedstructurally through :class:`ModeloFindingLike`; the implementation is:class:`cadrumo.domain.filing.schema.ModeloValidationFinding`."""from__future__importannotationsfromcollections.abcimportIterable,Iterator,MappingfromdatetimeimportdatefromtypingimportTYPE_CHECKING,Protocol,runtime_checkablefrom...core.auth_providerimportAuthProviderDescriptionfrom...core.errors.severityimportBaseSeverityfrom.modelsimportModeloPresentadoifTYPE_CHECKING:# pragma: no cover — type-only importfromcadrumo.domain.calculations.registry.tax_id_formatimportSubjectTaxIdfrom...core.periodimportPeriod
[docs]@runtime_checkableclassAuthProviderProbe(Protocol):"""Narrow submission-facing auth-provider surface."""@propertydefkind(self)->object:"""Provider kind identifier consumed by the preflight gate."""...
[docs]defdescribe(self)->AuthProviderDescription:"""Return the active provider's :class:`core.auth_provider.AuthProviderDescription`."""...
[docs]@runtime_checkableclassDeadlineWindowChecker(Protocol):"""Narrow surface over :mod:`cadrumo.domain.deadlines` for the preflight gate."""
[docs]defis_window_open(self,modelo:str,period:Period,today:date)->bool:"""Return ``True`` iff the AEAT filing window for ``modelo`` / ``period`` is open on ``today``."""...
[docs]@runtime_checkableclassModeloFindingLike(Protocol):"""Narrow structural port over one ``draft.findings`` entry. The implementation declares ``severity`` as a REQUIRED field with no default: :class:`cadrumo.domain.filing.schema.ModeloValidationFinding`. Typing :attr:`ModeloDraftLike.findings` through this Protocol (rather than ``tuple[object, ...]``) lets the preflight gate read ``.severity`` directly instead of through a ``getattr(..., None)`` guess -- a field rename now fails loud instead of silently excluding every finding from the error-severity gate. """@propertydefseverity(self)->BaseSeverity:"""Return the severity the preflight error-findings gate reads."""...
[docs]@runtime_checkableclassModeloDraftLike(Protocol):"""Narrow surface over a filing draft. :class:`domain.filing.schema.ModeloDraft` structurally conforms to this Protocol so the engine can accept either the real draft or any Protocol-conforming hand-rolled class in tests. Attributes are declared as read-only properties so pyrefly treats them covariantly and frozen pydantic models satisfy the protocol without invariance errors. """@propertydefdraft_id(self)->str:"""Return the draft's stable identifier."""...@propertydefmodelo(self)->str:"""Return the AEAT modelo this draft files."""...@propertydefperiod(self)->Period:"""Return the filing period the draft covers."""...@propertydefprofile_tax_id(self)->SubjectTaxId:"""Return the NIF / NIE of the taxpayer the draft is built for."""...@propertydefstatus(self)->object:"""Return the draft's lifecycle status. Declared as :class:`object` so any draft implementation satisfies the Protocol; the preflight gate compares against :class:`cadrumo.domain.submission.models.ModeloDraftStatus`. """...@propertydefvalues(self)->Mapping[str,str]|Iterable[object]:"""Return the draft's casilla values, keyed or iterable by implementation."""...@propertydeffindings(self)->tuple[ModeloFindingLike,...]:"""Return the validation findings the error-severity gate reads."""...
[docs]@runtime_checkableclassSubmissionRepositoryProtocol(Protocol):"""Narrow domain-facing repository contract for the submission engine. The concrete :class:`~cadrumo.adapters.persistence.profile.submission.SubmissionRepository` lives in the persistence adapter and inherits from the adapter-layer :class:`~cadrumo.adapters.persistence.storage.envelope.secure_bound_repository.SecureBoundRepository`. This Protocol captures only the surface the engine consumes so the domain depends inward on this port, and the application layer constructs the concrete repository and injects it into :class:`SubmissionEngine`. """
[docs]defload(self,record_id:str,/)->ModeloPresentado|None:"""Load a persisted :class:`ModeloPresentado` by id, or return None if absent."""...
[docs]defiter_submissions(self)->Iterator[ModeloPresentado]:"""Yield every persisted submission in lexicographic id order. Returns: Iterator over :class:`ModeloPresentado` records. """...
[docs]deflist_submission_ids(self)->tuple[str,...]:"""Return every submission id persisted in this repository."""...