import sqlalchemy as sa from email_campaigns.adapters.db import Repository from email_campaigns.rosters.models import ( ArtistRosterLocalRep, ArtistRosterMainRep, CustomList, ) class CustomListRepository(Repository[CustomList]): def get_allowed( self, custom_list_id: str, vendor_ids: list[int], subaccount_ids: list[int] ) -> CustomList | None: query = self.db.query_from_template( "custom-list/get-allowed-custom-list.sql", context={ "custom_list_id": custom_list_id, "vendor_ids": vendor_ids, "subaccount_ids": subaccount_ids, }, ) result = self.db.session.execute(sa.select(CustomList).from_statement(query)) return result.scalar_one_or_none() class ArtistRosterMainRepRepository(Repository[ArtistRosterMainRep]): def exists_by_account_and_global_participant_id( self, vendor_id: int, subaccount_id: int, global_participant_id: str ) -> bool: stmt = sa.select( sa.select(1) .exists() .where( ArtistRosterMainRep.vendor_id == vendor_id, ArtistRosterMainRep.subaccount_id == subaccount_id, ArtistRosterMainRep.global_participant_id == global_participant_id, ) ) result = self.db.session.execute(stmt) return bool(result.scalar_one()) class ArtistRosterLocalRepRepository(Repository[ArtistRosterLocalRep]): def exists_by_account_and_global_participant_id( self, vendor_id: int, subaccount_id: int, global_participant_id: str ) -> bool: stmt = sa.select( sa.select(1) .exists() .where( ArtistRosterLocalRep.vendor_id == vendor_id, ArtistRosterLocalRep.subaccount_id == subaccount_id, ArtistRosterLocalRep.global_participant_id == global_participant_id, ) ) result = self.db.session.execute(stmt) return bool(result.scalar_one())