"""Catalogue-level verification for :mod:`aeat.domain.iva`.Runs cross-record checks on top of the per-model validation that pydanticalready performs:* Every :class:`aeat.domain.iva.IvaCategory` member must be present.* Every regulation must carry at least one :class:`aeat.domain.iva.IvaCitation`.* Every citation must have non-empty :attr:`aeat.domain.iva.IvaCitation.quoted_text`.* Every ``boe_references`` id must match the kebab-case document-id shape used by the registry legal catalogue."""from__future__importannotationsimportrefrom...core.loggingimportget_loggerfrom._schemaimport(IvaCatalogue,IvaCategory,IvaVerificationIssue,IvaVerificationReport,)_logger=get_logger(__name__)_NORMATIVE_ID_PATTERN=re.compile(r"^[a-z0-9][a-z0-9-]*$")
[docs]defverify_catalogue(catalogue:IvaCatalogue)->IvaVerificationReport:"""Run every cross-record check on ``catalogue``. Args: catalogue: The :class:`aeat.domain.iva.IvaCatalogue` under audit. Returns: A :class:`aeat.domain.iva.IvaVerificationReport` aggregating every finding. """issues:list[IvaVerificationIssue]=[]present=set(catalogue.regulations.keys())missing=[memberformemberinIvaCategoryifmembernotinpresent]formemberinmissing:issues.append(IvaVerificationIssue(level="error",code="missing_category",message=f"catalogue does not cover IvaCategory.{member.name}",category_id=member.value,),)forregulationincatalogue:ifnotregulation.citations:issues.append(IvaVerificationIssue(level="error",code="missing_citation",message="regulation has no IvaCitation records",category_id=regulation.category.value,),)forcitationinregulation.citations:ifnotcitation.quoted_text.strip():issues.append(IvaVerificationIssue(level="error",code="empty_quoted_text",message=f"citation {citation.article!r} has empty quoted_text",category_id=regulation.category.value,),)forrefinregulation.boe_references:ifnot_NORMATIVE_ID_PATTERN.fullmatch(ref):issues.append(IvaVerificationIssue(level="error",code="invalid_legal_reference_id",message=f"boe_reference {ref!r} is not a kebab-case legal reference id",category_id=regulation.category.value,),)_logger.debug("verify_catalogue produced %d issue(s)",len(issues))returnIvaVerificationReport(issues=tuple(issues))