"""Encrypted SQL repository for the modelo work-unit catalogue.:class:`~aeat.domain.modelos.WorkUnitCatalogueRepository` persists:class:`WorkUnit` records in a :class:`WorkUnitCatalogue` at``FINANCIAL`` :class:`~aeat.adapters.persistence.storage.SensitivityClass`through:class:`~aeat.adapters.persistence.storage.SecureObjectRepository`. Thecatalogue is serialised as a single:class:`~aeat.adapters.persistence.storage.Envelope`-wrapped JSON payload keyedby a stable namespace and object key; the underlying column is encrypted so noplaintext work-unit metadata lands on disk.The storage contract is declared by:data:`aeat.adapters.persistence.storage.MODELO_WORK_UNIT_CATALOGUE_NAMESPACE`;its default object key is the singleton ``catalogue`` row."""from__future__importannotationsfrom._errorsimportModeloErrorfrom._work_unitimportWorkUnit,WorkUnitCatalogue_WORK_UNIT_NAMESPACE="aeat.domain.modelos.work_units"_WORK_UNIT_OBJECT_KEY="catalogue"_WORK_UNIT_CATALOGUE_VERSION=1
[docs]classWorkUnitPersistenceError(ModeloError):"""Raised when the work-unit catalogue cannot be loaded or saved. This wraps storage-boundary failures from :class:`~aeat.domain.modelos.WorkUnitCatalogueRepository` while preserving translated recovery context for callers. """
[docs]defupsert_work_unit(catalogue:WorkUnitCatalogue,unit:WorkUnit)->WorkUnitCatalogue:"""Return a new :class:`WorkUnitCatalogue` with ``unit`` inserted or replaced. The input catalogue is not mutated. The returned catalogue carries the same work units as the input plus ``unit`` at its deterministic ``work_unit_id``; any existing entry under that id is replaced. """mapping=dict(catalogue.work_units)mapping[unit.work_unit_id]=unitreturnWorkUnitCatalogue(work_units=mapping)
[docs]defremove_work_unit(catalogue:WorkUnitCatalogue,work_unit_id:str)->WorkUnitCatalogue:"""Return a new catalogue with ``work_unit_id`` removed. Removing an absent id is a no-op that returns a value-equal catalogue. The original is not mutated. Returns: A :class:`WorkUnitCatalogue` without the given work unit. """ifwork_unit_idnotincatalogue.work_units:returncataloguemapping=dict(catalogue.work_units)delmapping[work_unit_id]returnWorkUnitCatalogue(work_units=mapping)