from collections.abc import Sequence from pydantic import TypeAdapter from dmp.adapters.db import ReportingDB, ReportingRepository from dmp.config import Settings from dmp.songwhip.dtos import SongwhipPresavePage from dmp.songwhip.models import SongwhipPresavePageDbt SongwhipPresavePageList = TypeAdapter(list[SongwhipPresavePage]) class SongwhipPresavePageRepository(ReportingRepository[SongwhipPresavePageDbt]): def __init__(self, db: ReportingDB, settings: Settings) -> None: super().__init__(db) self.settings = settings def get_presave_pages( self, vendor_ids: list[int], subaccount_ids: list[int], global_participant_ids: list[str] | None, presave_page_ids: list[str] | None, ) -> Sequence[SongwhipPresavePage]: template_name = "presave-pages/find-by-criteria.sql" query = self.db.query_from_template( template_name, context={ "vendor_ids": vendor_ids, "subaccount_ids": subaccount_ids, "global_participant_ids": global_participant_ids, "presave_page_ids": presave_page_ids, }, ) response = self.db.session.execute(query).mappings() return SongwhipPresavePageList.validate_python( response, context={"songwhip_url": self.settings.songwhip_url}, )