import decimal from anydi import singleton from fansifter_common.auth.types import Permission from dmp.artists.cache import ArtistCache, cached_artist_data from dmp.artists.repositories import ArtistMaxSpendRepository from dmp.artists.requests import ArtistFanReportFilterRequest from dmp.artists.services import ArtistAccessService class GetArtistMaxSpendRequest(ArtistFanReportFilterRequest): pass @singleton class GetArtistMaxSpendHandler: permission = Permission("fan_data_list", "view") def __init__( self, artist_access_service: ArtistAccessService, artist_max_spend_repository: ArtistMaxSpendRepository, artist_cache: ArtistCache, ) -> None: self.artist_access_service = artist_access_service self.artist_max_spend_repository = artist_max_spend_repository self.artist_cache = artist_cache def handle(self, request: GetArtistMaxSpendRequest) -> decimal.Decimal: artist_access = self.artist_access_service.check_artist_access( request.identity_id, request.global_participant_id, request.account, permission=self.permission, ) return self._get_max_spend( request.global_participant_id, vendor_id=request.vendor_id, subaccount_id=request.subaccount_id, is_global=artist_access.is_global, ) @cached_artist_data("max-spend") def _get_max_spend( self, global_participant_id: str, vendor_id: int | None, subaccount_id: int | None, is_global: bool, ) -> decimal.Decimal: return self.artist_max_spend_repository.get_max_spend( vendor_id=vendor_id, subaccount_id=subaccount_id, global_participant_ids=[global_participant_id], is_global=is_global, )