from typing import List from sqlmodel import Session, select from infrastructure.postgres.property_table import PropertyRow from repositories.condition.property_reference_reader import ( PropertyReference, PropertyReferenceReader, ) class PropertyReferenceReaderPostgres(PropertyReferenceReader): """Reads landlord-reference -> UPRN pairs from the ``property`` table for a portfolio. The reference key is ``landlord_property_id`` (ADR-0064).""" def __init__(self, session: Session) -> None: self._session = session def references_for_portfolio(self, portfolio_id: int) -> List[PropertyReference]: rows = self._session.exec( select(PropertyRow.landlord_property_id, PropertyRow.uprn).where( PropertyRow.portfolio_id == portfolio_id ) ).all() return [ PropertyReference(landlord_property_id=landlord_property_id, uprn=uprn) for landlord_property_id, uprn in rows ]