import decimal from dataclasses import dataclass from anydi import singleton from fansifter_common.auth.requests import AuthAccountRequest from fansifter_common.auth.services import AuthService from fansifter_common.auth.types import Permission from dmp.artists.repositories import ArtistMaxSpendRepository @dataclass class GetShopifyMaxSpendRequest(AuthAccountRequest): global_participant_ids: list[str] @singleton class GetShopifyMaxSpendHandler: permission = Permission("fan_data_channel", "view") def __init__( self, auth_service: AuthService, artist_max_spend_repository: ArtistMaxSpendRepository, ) -> None: self.auth_service = auth_service self.artist_max_spend_repository = artist_max_spend_repository def handle(self, request: GetShopifyMaxSpendRequest) -> decimal.Decimal: self.auth_service.authorize_account( request.identity_id, permission=self.permission, account=request.account ) return self.artist_max_spend_repository.get_max_spend( vendor_id=request.vendor_id, subaccount_id=request.subaccount_id, global_participant_ids=request.global_participant_ids, )